出于某种原因;尽管我在验证中编码正确,但即使抛出异常,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);
}
最佳答案
刚刚意识到捕获异常会覆盖抛出 没关系
关于java - JUnit 4 没有捕获抛出的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47463332/