JUnit的文件
public class SomeClassTest {
...
@Test
public void testSomeContextFailure() throws Exception {
SomeClass sc = new SomeClass();
try {
sc.SomeContext(null,null);
fail("IllegalArg expected");
} catch (IllegalArgumentException e) {}
}
@Test
public void testSomeContextSuccess() throws Exception {
SomeClass sc = new SomeClass();
SomeContext in = new SomeContext();
in.setName("something");
in.setId("5");
in.setPoints(SomePoint.X);
try {
assertNotNull(sc.SomeContext(in,null));
} catch (Exception e) {}
}
}
Java文件
public class SomeClassTest {
@Autowired(required = true)
private InsuredDAO insuredDAO;
@Override
public context SomeContext(context c, unused u) throws Exception {
if(c == null)
throw new IllegalArgumentException();
insuredDAO.increaseValue(c);
if(c.getPoints() != null) {
...do something
}
return c;
}
在Java文件if(c == null)
强调了黄色用消息说1 2的分支未被覆盖。
throw new IllegalArgumentException();
突出绿色
insuredDAO.increaseValue(c);
上面和下面的这条线的一切都是红色的
我在想什么? (JUnit测试通过了两个,但为什么它不是盖的)?