[英]JUnit 4 not picking up a thrown exception
由於某些原因; 盡管我正確地在驗證中編寫了代碼,但是即使拋出異常,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);
}
剛剛意識到捕獲異常將覆蓋拋出的沒關系
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.