Skip to content

Instantly share code, notes, and snippets.

@kroepke
Created April 1, 2014 22:10
Show Gist options
  • Save kroepke/9924153 to your computer and use it in GitHub Desktop.
Save kroepke/9924153 to your computer and use it in GitHub Desktop.
private final Set<AssertionError> assertionErrors = Sets.newHashSet();
@BeforeTest
public void assertErrorTrap() {
assertionErrors.clear();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
if (e instanceof AssertionError) {
assertionErrors.add((AssertionError) e);
}
}
});
}
@AfterTest
public void checkThreadAssertions() {
assertEquals(assertionErrors.size(), 0, "Background threads should not fail assertions");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment