[英]Junit exception test
I have two tests to check the expected exception throw. 我有两个测试来检查预期的异常抛出。 I am using Junit 4 and has following syntax.
我正在使用Junit 4并具有以下语法。
@Test(expected=IllegalArgumentException.class)
public void testSomething(){
..........
}
One of the tests fail even though IllegalArgumentException is thrown and the other passes. 即使抛出IllegalArgumentException而另一个传递,其中一个测试也会失败。 Any idea whats missing??
有什么想法丢失? I modified the test which is failing to following and it passes.
我修改了未能跟随的测试并且它通过了。
public void testSomething(){
try{
............ //line that throws exception
fail();
}catch(IllegalArgumentException e) {
}
}
Prithis just something I noticed the second test does not have @Test annotation at all. Prithis只是我注意到第二次测试根本没有@Test注释。 JUNIT4 does not run tests that are not annotated even if the method names starts with test*** (unless of course you actually extend the TestCase class in which case it behaves like a JUNIT3.x testcase)
即使方法名称以test ***开头,JUNIT4也不会运行未注释的测试(除非您实际扩展TestCase类,在这种情况下它的行为类似于JUNIT3.x测试用例)
Perhaps that is the case that the test is not running at all (and hence makes you think that it passes)? 也许这就是测试根本没有运行的情况(因此让你觉得它通过了)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.