use of org.junit.runners.model.MultipleFailureException in project sling by apache.
the class TeleporterHttpClient method runTests.
void runTests(String testSelectionPath, int testReadyTimeoutSeconds) throws MalformedURLException, IOException, MultipleFailureException {
final String testUrl = baseUrl + "/" + testServletPath + testSelectionPath + ".junit_result";
// Wait for non-404 response that signals that test bundle is ready
final long timeout = System.currentTimeMillis() + (testReadyTimeoutSeconds * 1000L);
final ExponentialBackoffDelay delay = new ExponentialBackoffDelay(25, 1000);
while (true) {
if (getHttpGetStatus(testUrl).getStatus() == 200) {
break;
}
if (System.currentTimeMillis() > timeout) {
fail("Timeout waiting for test at " + testUrl + " (" + testReadyTimeoutSeconds + " seconds)");
break;
}
delay.waitNextDelay();
}
final HttpURLConnection c = (HttpURLConnection) new URL(testUrl).openConnection();
try {
setConnectionCredentials(c);
c.setRequestMethod("POST");
c.setUseCaches(false);
c.setDoOutput(true);
c.setDoInput(true);
c.setInstanceFollowRedirects(false);
final int status = c.getResponseCode();
if (status != 200) {
throw new IOException("Got status code " + status + " for " + testUrl);
}
final Result result = (Result) new ObjectInputStream(c.getInputStream()).readObject();
if (result.getFailureCount() > 0) {
final List<Throwable> failures = new ArrayList<Throwable>(result.getFailureCount());
for (Failure f : result.getFailures()) {
failures.add(f.getException());
}
throw new MultipleFailureException(failures);
}
} catch (ClassNotFoundException e) {
throw new IOException("Exception reading test results:" + e, e);
} finally {
cleanup(c);
}
}
use of org.junit.runners.model.MultipleFailureException in project junit4 by junit-team.
the class ExternalResourceRuleTest method shouldWrapAssumptionFailuresWhenClosingResourceFails.
@Test
public void shouldWrapAssumptionFailuresWhenClosingResourceFails() throws Throwable {
// given
final AtomicReference<Throwable> externalResourceException = new AtomicReference<Throwable>();
ExternalResource resourceRule = new ExternalResource() {
@Override
protected void after() {
RuntimeException runtimeException = new RuntimeException("simulating resource tear down failure");
externalResourceException.set(runtimeException);
throw runtimeException;
}
};
final AtomicReference<Throwable> assumptionViolatedException = new AtomicReference<Throwable>();
Statement skippedTest = new Statement() {
@Override
public void evaluate() throws Throwable {
AssumptionViolatedException assumptionFailure = new AssumptionViolatedException("skip it");
assumptionViolatedException.set(assumptionFailure);
throw assumptionFailure;
}
};
Description dummyDescription = Description.createTestDescription("dummy test class name", "dummy test name");
try {
resourceRule.apply(skippedTest, dummyDescription).evaluate();
fail("ExternalResource should throw");
} catch (MultipleFailureException e) {
assertThat(e.getFailures(), hasItems(instanceOf(TestCouldNotBeSkippedException.class), sameInstance(externalResourceException.get())));
assertThat(e.getFailures(), hasItems(hasCause(sameInstance(assumptionViolatedException.get())), sameInstance(externalResourceException.get())));
}
}
use of org.junit.runners.model.MultipleFailureException in project randomizedtesting by randomizedtesting.
the class RandomizedRunner method wrapBeforeAndAfters.
/**
* Wrap before and after hooks.
*/
private Statement wrapBeforeAndAfters(Statement s, final TestCandidate c, final Object instance) {
// Process @Before hooks. The first @Before to fail will immediately stop processing any other @Befores.
final List<Method> befores = getShuffledMethods(Before.class);
if (!befores.isEmpty()) {
final Statement afterBefores = s;
s = new Statement() {
@Override
public void evaluate() throws Throwable {
for (Method m : befores) {
invoke(m, instance);
}
afterBefores.evaluate();
}
};
}
// Process @After hooks. All @After hooks are processed, regardless of their own exceptions.
final List<Method> afters = getShuffledMethods(After.class);
if (!afters.isEmpty()) {
final Statement beforeAfters = s;
s = new Statement() {
@Override
public void evaluate() throws Throwable {
List<Throwable> cumulative = new ArrayList<Throwable>();
try {
beforeAfters.evaluate();
} catch (Throwable t) {
cumulative.add(t);
}
// All @Afters must be called.
for (Method m : afters) {
try {
invoke(m, instance);
} catch (Throwable t) {
cumulative.add(t);
}
}
// At end, throw the exception or propagete.
if (cumulative.size() == 1) {
throw cumulative.get(0);
} else if (cumulative.size() > 1) {
throw new MultipleFailureException(cumulative);
}
}
};
}
return s;
}
use of org.junit.runners.model.MultipleFailureException in project neo4j by neo4j.
the class TestData method apply.
@Override
public Statement apply(final Statement base, final Description description) {
final Title title = description.getAnnotation(Title.class);
final Documented doc = description.getAnnotation(Documented.class);
GraphDescription.Graph g = description.getAnnotation(GraphDescription.Graph.class);
if (g == null) {
g = description.getTestClass().getAnnotation(GraphDescription.Graph.class);
}
final GraphDescription graph = GraphDescription.create(g);
return new Statement() {
@Override
public void evaluate() throws Throwable {
product.set(create(graph, title == null ? null : title.value(), doc == null ? null : doc.value(), description.getMethodName()));
try {
try {
base.evaluate();
} catch (Throwable err) {
try {
destroy(get(false), false);
} catch (Throwable sub) {
List<Throwable> failures = new ArrayList<Throwable>();
if (err instanceof MultipleFailureException) {
failures.addAll(((MultipleFailureException) err).getFailures());
} else {
failures.add(err);
}
failures.add(sub);
throw new MultipleFailureException(failures);
}
throw err;
}
destroy(get(false), false);
} finally {
product.set(null);
}
}
};
}
use of org.junit.runners.model.MultipleFailureException in project spock by spockframework.
the class JUnitSupervisor method handleMultipleFailures.
// for better JUnit compatibility, e.g when a @Rule is used
private int handleMultipleFailures(ErrorInfo error) {
MultipleFailureException multiFailure = (MultipleFailureException) error.getException();
int runStatus = OK;
for (Throwable failure : multiFailure.getFailures()) runStatus = error(new ErrorInfo(error.getMethod(), failure));
return runStatus;
}
Aggregations