You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know about @Test(expectedExceptions=...), but with Java 8 officially out, testng could provide more fine-tuned asserting. I'm thinking of something like:
public interface ExceptionalRunnable {
public void run() throws Exception;
}
assertException(ExceptionalRunnable runnable, Class<? extends Throwable> expected) {
...
}
This would be backwards-compatible, though probably too verbose to be very useful for Java 7 or previous. But in Java 8, you can succinctly write something like:
This finer-grained control would help cut down on false positives. For instance, let's say you're expecting an NPE. If the test itself contained an NPE, it would pass even if the actual method you want to test didn't NPE -- possibly before it even got invoked. If you used assertException instead, and didn't include expectedExceptions in the @Test annotation, the test would fail as it should.
The text was updated successfully, but these errors were encountered:
I know about
@Test(expectedExceptions=...)
, but with Java 8 officially out, testng could provide more fine-tuned asserting. I'm thinking of something like:This would be backwards-compatible, though probably too verbose to be very useful for Java 7 or previous. But in Java 8, you can succinctly write something like:
This finer-grained control would help cut down on false positives. For instance, let's say you're expecting an NPE. If the test itself contained an NPE, it would pass even if the actual method you want to test didn't NPE -- possibly before it even got invoked. If you used
assertException
instead, and didn't includeexpectedExceptions
in the@Test
annotation, the test would fail as it should.The text was updated successfully, but these errors were encountered: