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)
中以黄色突出显示,消息说 2 个分支中的 1 个未覆盖。
throw new IllegalArgumentException();
突出显示的绿色
insuredDAO.increaseValue(c);
这条线上下的所有东西都是红色的
我错过了什么?(两者都通过了 JUnit 测试,但为什么不包括在内)?