use of org.junit.runner.notification.Failure in project cucumber-jvm by cucumber.
the class JUnitReporterTest method resultWithError.
@Test
public void resultWithError() {
createNonStrictReporter();
Result result = mock(Result.class);
Throwable exception = mock(Throwable.class);
when(result.getError()).thenReturn(exception);
Description description = mock(Description.class);
createRunNotifier(description);
jUnitReporter.result(result);
ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
Failure failure = failureArgumentCaptor.getValue();
assertEquals(description, failure.getDescription());
assertEquals(exception, failure.getException());
}
use of org.junit.runner.notification.Failure in project h2o-3 by h2oai.
the class H2OTestRunner method run.
public Result run(String[] args) throws Exception {
// List all classes - adapted from JUnitCore code
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Failure> missingClasses = new ArrayList<Failure>();
for (String arg : args) {
try {
classes.add(Class.forName(arg));
} catch (ClassNotFoundException e) {
Description description = Description.createSuiteDescription(arg);
Failure failure = new Failure(description, e);
missingClasses.add(failure);
}
}
// Create standard JUnitCore
JUnitCore jcore = new JUnitCore();
// Create default "system"
JUnitSystem jsystem = new RealSystem();
// Setup default listener
jcore.addListener(new TextListener(jsystem));
// Add XML generator listener
jcore.addListener(new XMLTestReporter());
Result result = jcore.run(classes.toArray(new Class[0]));
for (Failure each : missingClasses) {
System.err.println("FAIL Missing class in H2OTestRunner: " + each);
result.getFailures().add(each);
}
return result;
}
use of org.junit.runner.notification.Failure in project junit4 by junit-team.
the class StackTracesTest method getTrimmedStackForJUnit3TestFailingInTestMethod.
@Test
public void getTrimmedStackForJUnit3TestFailingInTestMethod() {
Result result = runTest(JUnit3TestWithOneThrowingTestMethod.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$JUnit3TestWithOneThrowingTestMethod.testAlwaysThrows"));
assertNotEquals(failure.getTrace(), failure.getTrimmedTrace());
}
use of org.junit.runner.notification.Failure in project junit4 by junit-team.
the class StackTracesTest method getTrimmedStackForJUnit4TestFailingInTestMethodWithCause.
@Test
public void getTrimmedStackForJUnit4TestFailingInTestMethodWithCause() {
Result result = runTest(TestWithOneThrowingTestMethodWithCause.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: outer"), at("org.junit.internal.StackTracesTest$FakeClassUnderTest.doThrowExceptionWithCause"), at("org.junit.internal.StackTracesTest$FakeClassUnderTest.throwsExceptionWithCause"), at("org.junit.internal.StackTracesTest$TestWithOneThrowingTestMethodWithCause.alwaysThrows"), framesTrimmed(), message("Caused by: java.lang.RuntimeException: cause"), at("org.junit.internal.StackTracesTest$FakeClassUnderTest.doThrowExceptionWithoutCause"), at("org.junit.internal.StackTracesTest$FakeClassUnderTest.throwsExceptionWithoutCause"), at("org.junit.internal.StackTracesTest$FakeClassUnderTest.doThrowExceptionWithCause"), framesInCommon());
assertNotEquals(failure.getTrace(), failure.getTrimmedTrace());
}
use of org.junit.runner.notification.Failure in project junit4 by junit-team.
the class StackTracesTest method getTrimmedStackForJUnit3TestFailingInSetupMethod.
@Test
public void getTrimmedStackForJUnit3TestFailingInSetupMethod() {
Result result = runTest(JUnit3TestWithThrowingSetUpMethod.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$JUnit3TestWithThrowingSetUpMethod.setUp"));
assertNotEquals(failure.getTrace(), failure.getTrimmedTrace());
}
Aggregations