Search in sources :

Example 6 with Failure

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

the class StackTracesTest method getTrimmedStackForJUnit4TestFailingInMethodRule.

@Test
public void getTrimmedStackForJUnit4TestFailingInMethodRule() {
    Result result = runTest(TestWithThrowingMethodRule.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$ThrowingMethodRule.apply"));
    assertNotEquals(failure.getTrace(), failure.getTrimmedTrace());
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 7 with Failure

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

the class StackTracesTest method getTrimmedStackForJUnit4TestFailingInTestRule.

@Test
public void getTrimmedStackForJUnit4TestFailingInTestRule() {
    Result result = runTest(TestWithThrowingTestRule.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$ThrowingTestRule.apply"));
    assertNotEquals(failure.getTrace(), failure.getTrimmedTrace());
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 8 with Failure

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

the class StackTracesTest method getTrimmedStackForJUnit4TestFailingInBeforeMethod.

@Test
public void getTrimmedStackForJUnit4TestFailingInBeforeMethod() {
    Result result = runTest(TestWithThrowingBeforeMethod.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$TestWithThrowingBeforeMethod.alwaysThrows"));
    assertNotEquals(failure.getTrace(), failure.getTrimmedTrace());
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 9 with Failure

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

Example 10 with Failure

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));
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) ArrayList(java.util.ArrayList) Failure(org.junit.runner.notification.Failure) InvalidTestClassError(org.junit.runners.model.InvalidTestClassError) 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