JUnit accuracy/failure/stress test区别
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

参考资料
JUnit4:Test注解的两个属性:expected和timeout
JUnit accuracy/failure/stress test区别的更多相关文章
- JUnit pass/failure/error区别
pass:被测程序没有抛出异常,得到的是预期的值. failure:被测程序的逻辑有错误,得不到预期的值.执行了JUnit的断言. error:被测程序本身抛出异常,还没有执行到JUnit的断言就抛出 ...
- junit中@Before和@BeforeClass区别
@before 在每个测试方法之前都执行一次, 方法需要声明为public @beforeclass 只在类中执行一次, 必须声明为public static
- PR曲线,ROC曲线,AUC指标等,Accuracy vs Precision
作为机器学习重要的评价指标,标题中的三个内容,在下面读书笔记里面都有讲: http://www.cnblogs.com/charlesblc/p/6188562.html 但是讲的不细,不太懂.今天又 ...
- 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 ...
- JUnit----单元测试
为什么进行单元测试? 1. 重用测试, 应付将来实现的变化. 2. 明确指定我的东西是没问题的. Failure, error的区别? Failure只测试失败, Error指程序本身出错 1. ne ...
- 【原】AFNetworking源码阅读(四)
[原]AFNetworking源码阅读(四) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇还遗留了很多问题,包括AFURLSessionManagerTaskDe ...
- hadoop2.2编程:MRUnit测试
引用地址:http://www.cnblogs.com/lucius/p/3442381.html examples: Overview This document explains how to w ...
- hadoop2.2编程:MRUnit
examples: Overview This document explains how to write unit tests for your map reduce code, and test ...
- selenium3 TestNG 介绍与配置
一.TestNG介绍 我之前有学习过Junit,Nunit 这些工具,现在想看看TestNG,那么TestNG是什么呢?他们之间有什么区别呢? TestNG(Next Generation)是一个测试 ...
随机推荐
- Python3学习笔记10-条件控制
Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块 var1 = 100 if var1: print("1 - if 表达式条件为 true&q ...
- openstack swift节点安装手册1-节点配置
本文参照官方教程:http://docs.openstack.org/project-install-guide/object-storage/draft/environment-networking ...
- mysql主从配置 转自http://www.cnblogs.com/sustudy/p/4174189.html
1.确保主数据库与从数据库一模一样. 例如:主数据库里的a的数据库里有b,c,d表,那从数据库里的就应该有一个模子刻出来的a的数据库和b,c,d表 2.在主数据库上创建同步账号. GRANT REPL ...
- yum install oracle-validated
背景 当时心血来潮要在linux搞oracle,可一顿折腾,大约两个周时间,主要是各种环境的检测麻烦,在redhat上操作也不如centos有利. 命令 yum install oracle-vali ...
- CSS高度塌陷问题解决方案
高度塌陷的存在:原因分析 1 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /& ...
- CentOS 6.5 rsync+inotify实现数据实时同步备份
CentOS 6.5 rsync+inotify实现数据实时同步备份 rsync remote sync 远程同步,同步是把数据从缓冲区同步到磁盘上去的.数据在内存缓存区完成之后还没有写入到磁盘 ...
- 解决walle报错:宿主机代码检出检测出错,请确认svn用户名密码无误
使用walle检测报错: 查看日志 # tail -f /tmp/walle/walle-20161010.log 报错: 2016-10-10 14:20:30 -- --------------- ...
- centos7的安装主要步骤选择
选择语言,选择英语 选择时区done确认选择 安全策略,选择默认 安装源文件 软件包选择,此处选择 最小安装 选择磁盘,并分区
- 转载:详解Java 自动装箱与拆箱的实现原理
原文:http://www.jb51.net/article/111847.htm 什么是自动装箱和拆箱 自动装箱就是Java自动将原始类型值转换成对应的对象,比如将int的变量转换成Integer对 ...
- selenium webdriver+python基本操作
# -*- coding:utf-8 -*-#导入模块from selenium import webdriver from selenium.common.exceptions import NoS ...