Search in sources :

Example 21 with Failure

use of org.junit.runner.notification.Failure in project junit4 by junit-team.

the class ExpectedTest method unexpected.

@Test
public void unexpected() {
    Result result = JUnitCore.runClasses(Unexpected.class);
    Failure failure = result.getFailures().get(0);
    String message = failure.getMessage();
    assertTrue(message.contains("expected<java.lang.Exception> but was<java.lang.Error>"));
    assertEquals(Error.class, failure.getException().getCause().getClass());
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 22 with Failure

use of org.junit.runner.notification.Failure in project junit4 by junit-team.

the class FailedConstructionTest method failedConstructionIsTestFailure.

@Test
public void failedConstructionIsTestFailure() {
    Result result = JUnitCore.runClasses(CantConstruct.class);
    Failure failure = result.getFailures().get(0);
    Description expected = Description.createTestDescription(CantConstruct.class, "foo");
    Assert.assertEquals(expected, failure.getDescription());
}
Also used : Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 23 with Failure

use of org.junit.runner.notification.Failure in project junit4 by junit-team.

the class TextListener method printFailures.

protected void printFailures(Result result) {
    List<Failure> failures = result.getFailures();
    if (failures.isEmpty()) {
        return;
    }
    if (failures.size() == 1) {
        getWriter().println("There was " + failures.size() + " failure:");
    } else {
        getWriter().println("There were " + failures.size() + " failures:");
    }
    int i = 1;
    for (Failure each : failures) {
        printFailure(each, "" + i++);
    }
}
Also used : Failure(org.junit.runner.notification.Failure)

Example 24 with Failure

use of org.junit.runner.notification.Failure in project junit4 by junit-team.

the class JUnit4ClassRunner method testAborted.

private void testAborted(RunNotifier notifier, Description description, Throwable e) {
    notifier.fireTestStarted(description);
    notifier.fireTestFailure(new Failure(description, e));
    notifier.fireTestFinished(description);
}
Also used : Failure(org.junit.runner.notification.Failure)

Example 25 with Failure

use of org.junit.runner.notification.Failure in project mockito by mockito.

the class UnnecessaryStubbingsReporter method validateUnusedStubs.

public void validateUnusedStubs(Class<?> testClass, RunNotifier notifier) {
    Collection<Invocation> unused = new UnusedStubbingsFinder().getUnusedStubbingsByLocation(mocks);
    if (unused.size() == 0) {
        //whoa!!! All stubbings were used!
        return;
    }
    //Oups, there are unused stubbings
    Description unnecessaryStubbings = Description.createTestDescription(testClass, "unnecessary Mockito stubbings");
    notifier.fireTestFailure(new Failure(unnecessaryStubbings, Reporter.formatUnncessaryStubbingException(testClass, unused)));
}
Also used : Description(org.junit.runner.Description) Invocation(org.mockito.invocation.Invocation) Failure(org.junit.runner.notification.Failure)

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