簡體   English   中英

JUnit 4未拾取引發的異常

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM