java比如@test是什么意思有什么用呢
具体是这样的publicclassHelloJunit{@Testpublicvoidtest(){System.out.println("ni");}那这个@test是...
具体是这样的
public class HelloJunit {
@Test
public void test(){
System.out.println("ni");
}
那这个@test是什么意思 展开
public class HelloJunit {
@Test
public void test(){
System.out.println("ni");
}
那这个@test是什么意思 展开
2个回答
展开全部
@是注解
@Test注解是JUnit测试的基础,它提供了其他作用
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());
}
}
@Test注解是JUnit测试的基础,它提供了其他作用
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());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询