1
我想使用JUnit 4.0来测试应用程序是否在布尔方法上返回期望的输出。JUnit assertTrue异常
测试类似于以下内容:
import org.junit.Test;
import static org.junit.Assert.*;
public class ExampleTest{
@Test
public void somethingTest(){
String [] words={"one","two","one","two","one","two","one","two"};
for(String word:words){
Example example = new Example(word);
if(word.startsWith("o")){
assertTrue(example.isO());
}else{
assertFalse(example.isO());
}
}
}
}
当我运行测试,这是正确的,做工精细的断言。虽然当我到失败的断言,抛出异常并且测试中断返回此堆栈:
java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:92)
at org.junit.Assert.assertTrue(Assert.java:43)
at org.junit.Assert.assertTrue(Assert.java:54)
at core.ExampleTest.somethingTest....
我需要的是测试正常进行,并给我一个号码在通过和失败的测试结束。我怎样才能做到这一点?