use of org.junit.runners.model.MultipleFailureException in project junit4 by junit-team.
the class ExternalResourceRuleTest method shouldThrowMultipleFailureExceptionWhenTestFailsAndClosingResourceFails.
@Test
public void shouldThrowMultipleFailureExceptionWhenTestFailsAndClosingResourceFails() throws Throwable {
// given
ExternalResource resourceRule = new ExternalResource() {
@Override
protected void after() {
throw new RuntimeException("simulating resource tear down failure");
}
};
Statement failingTest = new Fail(new RuntimeException("simulated test failure"));
Description dummyDescription = Description.createTestDescription("dummy test class name", "dummy test name");
try {
resourceRule.apply(failingTest, dummyDescription).evaluate();
fail("ExternalResource should throw");
} catch (MultipleFailureException e) {
assertThat(e.getMessage(), allOf(containsString("simulated test failure"), containsString("simulating resource tear down failure")));
}
}
use of org.junit.runners.model.MultipleFailureException in project junit4 by junit-team.
the class MultipleFailureExceptionTest method assertEmptyWrapsAssumptionFailuresForManyThrowables.
@Test
public void assertEmptyWrapsAssumptionFailuresForManyThrowables() throws Exception {
List<Throwable> errors = new ArrayList<Throwable>();
AssumptionViolatedException assumptionViolatedException = new AssumptionViolatedException("skip it");
errors.add(assumptionViolatedException);
errors.add(new RuntimeException("garlic"));
try {
MultipleFailureException.assertEmpty(errors);
fail();
} catch (MultipleFailureException expected) {
assertThat(expected.getFailures().size(), equalTo(2));
assertTrue(expected.getMessage().startsWith("There were 2 errors:" + LINE_SEPARATOR));
assertTrue(expected.getMessage().contains("TestCouldNotBeSkippedException(Test could not be skipped"));
assertTrue(expected.getMessage().contains("RuntimeException(garlic)"));
Throwable first = expected.getFailures().get(0);
assertThat(first, instanceOf(TestCouldNotBeSkippedException.class));
Throwable cause = ((TestCouldNotBeSkippedException) first).getCause();
assertThat(cause, instanceOf(AssumptionViolatedException.class));
assertThat((AssumptionViolatedException) cause, CoreMatchers.sameInstance(assumptionViolatedException));
}
}
use of org.junit.runners.model.MultipleFailureException in project junit4 by junit-team.
the class FailOnTimeout method createTimeoutException.
private Exception createTimeoutException(Thread thread) {
StackTraceElement[] stackTrace = thread.getStackTrace();
final Thread stuckThread = lookForStuckThread ? getStuckThread(thread) : null;
Exception currThreadException = new TestTimedOutException(timeout, timeUnit);
if (stackTrace != null) {
currThreadException.setStackTrace(stackTrace);
thread.interrupt();
}
if (stuckThread != null) {
Exception stuckThreadException = new Exception("Appears to be stuck in thread " + stuckThread.getName());
stuckThreadException.setStackTrace(getStackTrace(stuckThread));
return new MultipleFailureException(Arrays.<Throwable>asList(currThreadException, stuckThreadException));
} else {
return currThreadException;
}
}
use of org.junit.runners.model.MultipleFailureException in project randomizedtesting by randomizedtesting.
the class TestFailurePropagationCompatibility method maybeFail.
static void maybeFail() {
if (random != null) {
if (random.nextInt(frequency) == 0) {
if (random.nextBoolean()) {
throw new RuntimeException("State: " + random.nextLong());
} else {
ArrayList<Throwable> errors = new ArrayList<Throwable>();
errors.add(new RuntimeException("State: " + random.nextLong()));
errors.add(new RuntimeException("State: " + random.nextLong()));
// Throw MultipleFailureException as if unchecked.
Rethrow.rethrow(new MultipleFailureException(errors));
}
}
}
}
use of org.junit.runners.model.MultipleFailureException in project spock by spockframework.
the class JUnitSupervisor method error.
public int error(ErrorInfo error) {
Throwable exception = error.getException();
if (exception instanceof MultipleFailureException)
return handleMultipleFailures(error);
if (isFailedEqualityComparison(exception))
exception = convertToComparisonFailure(exception);
filter.filter(exception);
Failure failure = new Failure(getCurrentDescription(), exception);
if (exception instanceof AssumptionViolatedException) {
// do notify JUnit listeners unless it's a data-driven iteration that's reported as one feature
if (currentIteration == null || !currentFeature.isParameterized() || currentFeature.isReportIterations()) {
notifier.fireTestAssumptionFailed(failure);
}
} else {
masterListener.error(error);
notifier.fireTestFailure(failure);
}
errorSinceLastReset = true;
return statusFor(error);
}
Aggregations