accuracy test(结果准确性测试)

  例如,Assert.assertEquals(expected, actual)。

  如果结果不符合期望则产生failure。说明程序逻辑有问题。

  failure test(抛出异常测试)

  expected属性用来指示期望抛出的异常类型。例如,@Test(expected = IllegalArgumentException.class)。

  如果结果不符合期望则产生failure。说明程序逻辑有问题。

  stress test(运行时间测试)

  timeout属性用来指示时间上限,单位是毫秒。例如,@Test(timeout = 300)。

  如果超时则产生error。说明程序本身性能达不到要求。

  

  举个例子

  

 package edu.zju.cst.Student;

 public class Student {
private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String speak(String stm) {
try {
Thread.sleep(400);
} catch (InterruptedException e) {
e.printStackTrace();
} return name + ": " + stm;
}
}

Student.java

 package edu.zju.cst;

 import org.junit.After;
import org.junit.Before;
import org.junit.Test; import edu.zju.cst.Student.Student;
import junit.framework.Assert; public class StudentAccuracyTest {
private Student student; @Before
public void setUp() {
student = new Student();
student.setName("Tom");
} @Test
public void testSpeak() {
String expected = "Tom: hello";
String actual = student.speak("hell");
Assert.assertEquals(expected, actual);
} @After
public void tearDown() { }
}

StudentAccuracyTest.java

 package edu.zju.cst;

 import org.junit.After;
import org.junit.Before;
import org.junit.Test; import edu.zju.cst.Student.Student; public class StudentFailureTest {
private Student student; @Before
public void setUp() {
student = new Student();
student.setName("Tom");
} @Test(expected = IllegalArgumentException.class)
public void testSpeak() throws IllegalArgumentException {
student.speak("hell");
} @After
public void tearDown() { }
}

StudentFailureTest.java

 package edu.zju.cst;

 import org.junit.After;
import org.junit.Before;
import org.junit.Test; import edu.zju.cst.Student.Student; public class StudentStressTest {
private Student student; @Before
public void setUp() {
student = new Student();
student.setName("Tom");
} @Test(timeout = 300)
public void testSpeak() {
student.speak("hell");
} @After
public void tearDown() { }
}

StudentStressTest.java

 package edu.zju.cst;

 import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class)
@SuiteClasses({StudentAccuracyTest.class, StudentFailureTest.class,
StudentStressTest.class})
public class TestSuite { }

TestSuite.java

  

  参考资料

  JUnit单元测试的几个规律总结

  JUnit4:Test注解的两个属性:expected和timeout

JUnit accuracy/failure/stress test区别的更多相关文章

  1. JUnit pass/failure/error区别

    pass:被测程序没有抛出异常,得到的是预期的值. failure:被测程序的逻辑有错误,得不到预期的值.执行了JUnit的断言. error:被测程序本身抛出异常,还没有执行到JUnit的断言就抛出 ...

  2. junit中@Before和@BeforeClass区别

    @before 在每个测试方法之前都执行一次, 方法需要声明为public @beforeclass 只在类中执行一次, 必须声明为public static

  3. PR曲线,ROC曲线,AUC指标等,Accuracy vs Precision

    作为机器学习重要的评价指标,标题中的三个内容,在下面读书笔记里面都有讲: http://www.cnblogs.com/charlesblc/p/6188562.html 但是讲的不细,不太懂.今天又 ...

  4. How to Use JUnit With JMeter

    Do you need to use JUnit in your testing processes? To answer this question, let's take a look first ...

  5. JUnit----单元测试

    为什么进行单元测试? 1. 重用测试, 应付将来实现的变化. 2. 明确指定我的东西是没问题的. Failure, error的区别? Failure只测试失败, Error指程序本身出错 1. ne ...

  6. 【原】AFNetworking源码阅读(四)

    [原]AFNetworking源码阅读(四) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇还遗留了很多问题,包括AFURLSessionManagerTaskDe ...

  7. hadoop2.2编程:MRUnit测试

    引用地址:http://www.cnblogs.com/lucius/p/3442381.html examples: Overview This document explains how to w ...

  8. hadoop2.2编程:MRUnit

    examples: Overview This document explains how to write unit tests for your map reduce code, and test ...

  9. selenium3 TestNG 介绍与配置

    一.TestNG介绍 我之前有学习过Junit,Nunit 这些工具,现在想看看TestNG,那么TestNG是什么呢?他们之间有什么区别呢? TestNG(Next Generation)是一个测试 ...

随机推荐

  1. centos7使用haproxy1.7.5实现反向代理负载均衡实战

    使用haproxy实现反向代理负载均衡实战环境准备:两台虚拟机 # yum install -y gcc glibc gcc-c++ make screen tree lrzsz node1源码编译安 ...

  2. saltstack自动化运维系列11基于etcd的saltstack的自动化扩容

    saltstack自动化运维系列11基于etcd的saltstack的自动化扩容 自动化运维-基于etcd加saltstack的自动化扩容# tar -xf etcd-v2.2.1-linux-amd ...

  3. 用java实现邮件发送验证码

    java实现邮件发送验证码 建议不要用qq邮箱,我使用qq邮箱直接一直给我报530错误,我一直认为我代码写的有错误或者POP3/SMTP服务没弄好.所以建议注册个别的邮箱,我就申请了个网易163邮箱瞬 ...

  4. vue-router两种模式,到底什么情况下用hash,什么情况下用history模式呢?

    转:https://segmentfault.com/q/1010000010340823/a-1020000010598395 为什么要有 hash 和 history 对于 Vue 这类渐进式前端 ...

  5. 前端工程化-webpack(babel编译ES6)

    最新版安装与普通安装 使用babel-loader编译ES6,需要遵循规范,安装babel-presets 规范列表 对应babel-loader,babel-preset安装最新版和普通版: pre ...

  6. laravel 接口跨域

    最方便的方法,新建一个middleWare,把这个middleware加入到全局中间件,所有的请求,都会经过这个中间件的过滤. php artisan make:middleware CrossHtt ...

  7. poj2114 树分治(点分治)

    poj1741板子套一套,统计对数的方式改一下,可以在O(n)时间内统计对数 最后不要忘记输出最后的“.” /* 给定一棵边权树,是否存在一条路径使得其长度为恰好为x 把1741的板子改为求点对之间的 ...

  8. 步步为营-10-string的简单操作

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  9. each()遍历

    在<jQuery教程/理解选取更新范围>一节中,我们知道:当选择器返回了多个元素时,可以使用一个方法来更新所有的元素,不再需要使用循环. 然后有的时候需要遍历元素,怎么办? 使用each( ...

  10. 对象奔驰E2000

    <script> window.onload = function (ev) { // 调用对象前先创建 // 2 var vcar=new Car("奔驰",&quo ...