use of org.junit.runner.notification.Failure in project junit4 by junit-team.
the class StackTracesTest method getTrimmedStackForJUnit4TestFailingInTestMethod.
@Test
public void getTrimmedStackForJUnit4TestFailingInTestMethod() {
Result result = runTest(TestWithOneThrowingTestMethod.class);
assertEquals("Should run the test", 1, result.getRunCount());
assertEquals("One test should fail", 1, result.getFailureCount());
Failure failure = result.getFailures().get(0);
assertHasTrimmedTrace(failure, message("java.lang.RuntimeException: cause"), at("org.junit.internal.StackTracesTest$FakeClassUnderTest.doThrowExceptionWithoutCause"), at("org.junit.internal.StackTracesTest$FakeClassUnderTest.throwsExceptionWithoutCause"), at("org.junit.internal.StackTracesTest$TestWithOneThrowingTestMethod.alwaysThrows"));
assertNotEquals(failure.getTrace(), failure.getTrimmedTrace());
}
use of org.junit.runner.notification.Failure in project junit4 by junit-team.
the class ErrorReportingRunnerTest method givenInvalidTestClassErrorAsCause.
@Test
public void givenInvalidTestClassErrorAsCause() {
final List<Failure> firedFailures = new ArrayList<Failure>();
InvalidTestClassError testClassError = new InvalidTestClassError(TestClassWithErrors.class, Arrays.asList(new Throwable("validation error 1"), new Throwable("validation error 2")));
ErrorReportingRunner sut = new ErrorReportingRunner(TestClassWithErrors.class, testClassError);
sut.run(new RunNotifier() {
@Override
public void fireTestFailure(Failure failure) {
super.fireTestFailure(failure);
firedFailures.add(failure);
}
});
assertThat(firedFailures.size(), is(1));
Throwable exception = firedFailures.get(0).getException();
assertThat(exception, instanceOf(InvalidTestClassError.class));
assertThat(((InvalidTestClassError) exception), is(testClassError));
}
use of org.junit.runner.notification.Failure in project jersey by jersey.
the class ConcurrentParameterizedRunner method runChild.
@Override
protected void runChild(final FrameworkMethod method, final RunNotifier notifier) {
notifier.fireTestStarted(describeChild(method));
final Object testInstance;
try {
// get the test parameter iterator first
final List<FrameworkMethod> parameterMethods = getTestClass().getAnnotatedMethods(Parameterized.Parameters.class);
final Iterable<Object[]> parameters = (Iterable<Object[]>) parameterMethods.get(0).getMethod().invoke(null);
// then create the test instance
testInstance = super.createTest();
// now run the before methods
List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
for (FrameworkMethod before : befores) {
before.getMethod().invoke(testInstance);
}
// and launch as meny test method invocations as many parameters is available
final Iterator<Object[]> paramIterator = parameters.iterator();
final Method javaTestMethod = method.getMethod();
final AtomicInteger submitted = new AtomicInteger(0);
while (paramIterator.hasNext()) {
final Object[] javaMethodArgs = paramIterator.next();
submitted.incrementAndGet();
executor.submit(new Runnable() {
@Override
public void run() {
try {
javaTestMethod.invoke(testInstance, javaMethodArgs);
} catch (IllegalAccessException ex) {
notifier.fireTestFailure(new Failure(describeChild(method), ex));
} catch (IllegalArgumentException ex) {
notifier.fireTestFailure(new Failure(describeChild(method), ex));
} catch (InvocationTargetException ex) {
notifier.fireTestFailure(new Failure(describeChild(method), ex));
} finally {
submitted.decrementAndGet();
}
}
});
}
// wait until everything is done
while (submitted.intValue() > 0) {
LOGGER.info(String.format("Waiting for %d requests to finish...%n", submitted.intValue()));
try {
Thread.sleep(FINISH_WAIT_CYCLE_MS);
} catch (InterruptedException e) {
}
}
// and launch the after party..
List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods(After.class);
for (FrameworkMethod after : afters) {
after.getMethod().invoke(testInstance);
}
} catch (Exception ex) {
notifier.fireTestFailure(new Failure(describeChild(method), ex));
return;
}
notifier.fireTestFinished(describeChild(method));
}
use of org.junit.runner.notification.Failure in project jersey by jersey.
the class ConcurrentRunner method runThemAll.
private void runThemAll(final List<FrameworkMethod> methods, final RunNotifier notifier) {
final Object testInstance;
try {
testInstance = super.createTest();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
// run the before methods
List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
for (FrameworkMethod before : befores) {
try {
before.getMethod().invoke(testInstance);
} catch (Exception ex) {
LOGGER.log(java.util.logging.Level.SEVERE, null, ex);
}
final AtomicInteger submitted = new AtomicInteger(0);
for (final FrameworkMethod method : methods) {
try {
notifier.fireTestStarted(describeChild(method));
final Method javaTestMethod = method.getMethod();
final Object[] javaMethodArgs = new Object[] {};
submitted.incrementAndGet();
executor.submit(new Runnable() {
@Override
public void run() {
try {
javaTestMethod.invoke(testInstance, javaMethodArgs);
} catch (Exception ex) {
notifier.fireTestFailure(new Failure(describeChild(method), ex));
} finally {
submitted.decrementAndGet();
}
}
});
} catch (Exception ex) {
notifier.fireTestFailure(new Failure(describeChild(method), ex));
return;
}
notifier.fireTestFinished(describeChild(method));
}
// wait until everything is done
while (submitted.intValue() > 0) {
LOGGER.info(String.format("Waiting for %d requests to finish...%n", submitted.intValue()));
try {
Thread.sleep(FINISH_WAIT_CYCLE_MS);
} catch (InterruptedException e) {
}
}
// and launch the after party..
List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods(After.class);
for (FrameworkMethod after : afters) {
try {
after.getMethod().invoke(testInstance);
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, null, ex);
}
}
}
}
use of org.junit.runner.notification.Failure in project junit4 by junit-team.
the class ResultMatchersTest method hasFailureContaining_givenResultWithNoFailures.
@Test
public void hasFailureContaining_givenResultWithNoFailures() {
PrintableResult resultWithNoFailures = new PrintableResult(new ArrayList<Failure>());
assertThat(ResultMatchers.hasFailureContaining("").matches(resultWithNoFailures), is(false));
}
Aggregations