user8955547
user8955547

Reputation:

JUnit 4 not picking up a thrown exception

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);
 }

Upvotes: 0

Views: 53

Answers (1)

user8955547
user8955547

Reputation:

Just realised catching the exception overrides the throw nevermind

Upvotes: 1

Related Questions