0

For some reason; despite me coding in my validation correctly, JUnit 4 keeps raising a failure even if the exception is thrown:

code:

 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); } 
2
  • 1
    But you caught the exception right after throwing it. Commented Nov 23, 2017 at 21:14
  • @Törpetestű oooh Commented Nov 23, 2017 at 21:15

1 Answer 1

1

Just realised catching the exception overrides the throw nevermind

Sign up to request clarification or add additional context in comments.

Comments