Search in sources :

Example 96 with Failure

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());
}
Also used : Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 97 with Failure

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;
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) ArrayList(java.util.ArrayList) JUnitSystem(org.junit.internal.JUnitSystem) TextListener(org.junit.internal.TextListener) Result(org.junit.runner.Result) RealSystem(org.junit.internal.RealSystem) Failure(org.junit.runner.notification.Failure)

Example 98 with Failure

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());
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 99 with Failure

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());
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 100 with Failure

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());
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Aggregations

Failure (org.junit.runner.notification.Failure)190 Test (org.junit.Test)101 Result (org.junit.runner.Result)88 Description (org.junit.runner.Description)38 IOException (java.io.IOException)32 UnitTest (org.apache.geode.test.junit.categories.UnitTest)27 JUnitCore (org.junit.runner.JUnitCore)21 FileInputStream (java.io.FileInputStream)20 InputStream (java.io.InputStream)20 RunListener (org.junit.runner.notification.RunListener)18 ArrayList (java.util.ArrayList)10 ComparisonFailure (org.junit.ComparisonFailure)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)7 RunNotifier (org.junit.runner.notification.RunNotifier)7 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)6 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)5 Before (org.junit.Before)5 Request (org.junit.runner.Request)5 Runner (org.junit.runner.Runner)5