-1

Version: testng-6.8.8.jar

This test runs green:

@Test(expectedExceptions = { NullPointerException.class })
public void shouldTestNGIgnoreAssertsAfterExceptionThrown() throws Exception {
  String iAmNull = null;
  int length = iAmNull.length();
  assertEquals(0, 1);
}

Any config file or other options
to continue and evaluate asserts after the exception has taken place ?

user77115
  • 5,517
  • 6
  • 37
  • 40
  • TestNG is not able to know you have another assertions after the exception. You have to use try/catch in this case. – juherr Oct 02 '15 at 12:25

2 Answers2

2

You have to rewrite your test. For example:

@Test
public void shouldTestNGIgnoreAssertsAfterExceptionThrown() {
  String iAmNull = null;
  boolean hasNpe = false;
  try {
    int length = iAmNull.length();
  } catch(NullPointerException npe) {
    hasNpe = true;
  }
  assertTrue(hasNpe);
  assertEquals(0, 1);
}
juherr
  • 5,640
  • 1
  • 21
  • 63
2

It has nothing to do with TestNG. This is about how Java works (and should work). Any method call on null ( <nullObject>.someMethod() ) causes NullPointerException to be thrown. If you don't catch it in your method, it get's propagated up the call stack. If it's not handled anywhere, execution ends with stack trace.

automatictester
  • 2,436
  • 1
  • 19
  • 34