@Test注解
来源:互联网 发布:fft算法c语言实现 编辑:程序博客网 时间:2024/05/17 22:14
@Test表示这个方法是JUnit测试时候会运行的@Override表示这个方法是覆盖了父类的同名方法没有快捷键,这都属于java代码的一部分
追问
请问JUnit测试是什么?什么时候使用?@Test怎么使用?我在函数左上角直接打上去会报错,Test cannot be resolved to a type;
回答
你要引入junit.jar包,然后import org.junit.Test;
@Test注解是测试的基础,它提供了其他作用
1.指定将会抛出的异常类型,如果没有抛出异常或者抛出的一场不属于我们指定的类型,就会算是测试失败了。
@Test(expected = RuntimeException.class)
public void testGetHandlerNotDefined() {
SampleRequest request = new SampleRequest("testNotDefined");
// The following line is supposed to throw a RuntimeException
controller.getHandler(request);
}
2.测试一断代码运行时间。
@Test(timeout=100)
public void testProcessMultipleRequestsTimeout() {
Request request;
Response response = new SampleResponse();
RequestHandler handler = new SampleHandler();
for (int i = 0; i < 99999; i++) {
request = new SampleRequest(String.valueOf(i));
controller.addHandler(request, handler);
response = controller.processRequest(request);
Assert.assertNotNull(response);
Assert.assertNotSame(ErrorResponse.class, response.getClass());
}
}
3.在3.x版本中,如果我们不想启动某些测试,需要将方法名更改为非test开头的(3.X测试用例必须是以test开头)。而4版本只需添加一个注释@Ignore
0 0
- @Test注解
- @Override @Test @... 注解
- junit单元测试的Test注解
- 模拟@Test功能(注解)
- spring test+junit+dbunit注解及使用说明
- TestNG入门——注解之@Test
- springboot Test 自动配置注解详单
- 自定义test之dubbo注解的实现
- 写测试类时没有@Test注解
- 解读Junit的@Test注解,避免initializationerror
- Junit4注解@Test|@Before等使用
- spring使用注解做Test测试类
- 使用自定义注解完成@Test注解功能类似的效果
- 注解学习:实现简单的junit的@test注解
- 【笔记】JunitTest的@Test注解的两个参数
- 引入了junit为什么还是用不了@Test注解
- JUnit4中@Before、@After、@Test等注解的作用
- java中 @Test注解的使用和其他成员
- 【oj1953】字符个数统计
- MPI单节点启动问题
- ubuntu中./ 时 source not found 的解决方法
- 模板的概念及工作原理 .
- 10162 - Last Digit (数论+周期规律)
- @Test注解
- Linux 查看用户
- 请求码与结果码的作用
- IO操作
- 探索C++对象模型之struct和class区别
- 教你一步步做restful程序(2)
- 码农心得
- 取指定的字符串,字符串里面有汉字和字母
- The Differences Between MBR and GPT