出于某种原因;尽管我在我的验证中正确编码,但即使抛出异常,JUnit 4仍然会引发失败:
代码:
try {
if (firstname == null) {
throw new IllegalArgumentException("First name cannot be null");
}catch (IllegalArgumentException e) {
e.getMessage();
e.printStackTrace();
}
JUnit的:
@Test(expected=IllegalArgumentException.class)
public void testUserInvalidConstructions() {
User user = new User(null);
}
答案 0 :(得分:1)
刚刚意识到抓住异常会覆盖抛出 没关系