Search in sources :

Example 56 with Failure

use of org.junit.runner.notification.Failure in project lucene-solr by apache.

the class WithNestedTests method assertFailureCount.

protected void assertFailureCount(int expected, Result result) {
    if (result.getFailureCount() != expected) {
        StringBuilder b = new StringBuilder();
        for (Failure f : result.getFailures()) {
            b.append("\n\n");
            b.append(f.getMessage());
            b.append("\n");
            b.append(f.getTrace());
        }
        Assert.assertFalse("Expected failures: " + expected + " but was " + result.getFailureCount() + ", failures below: " + b.toString(), true);
    }
}
Also used : TestRuleMarkFailure(org.apache.lucene.util.TestRuleMarkFailure) Failure(org.junit.runner.notification.Failure)

Example 57 with Failure

use of org.junit.runner.notification.Failure in project lucene-solr by apache.

the class TestExceptionInBeforeClassHooks method testExceptionWithinTestFailsTheTest.

@Test
public void testExceptionWithinTestFailsTheTest() {
    Result runClasses = JUnitCore.runClasses(Nested2.class);
    assertFailureCount(3, runClasses);
    Assert.assertEquals(3, runClasses.getRunCount());
    ArrayList<String> foobars = new ArrayList<>();
    for (Failure f : runClasses.getFailures()) {
        Matcher m = Pattern.compile("foobar[0-9]+").matcher(f.getTrace());
        while (m.find()) {
            foobars.add(m.group());
        }
    }
    Collections.sort(foobars);
    Assert.assertEquals("[foobar1, foobar2, foobar3]", Arrays.toString(foobars.toArray()));
}
Also used : Matcher(java.util.regex.Matcher) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 58 with Failure

use of org.junit.runner.notification.Failure in project geode by apache.

the class ExpectedTimeoutRuleTest method failsWithExpectedTimeoutButWrongError.

@Test
public void failsWithExpectedTimeoutButWrongError() {
    Result result = TestRunner.runTest(FailsWithExpectedTimeoutButWrongError.class);
    assertThat(result.wasSuccessful()).isFalse();
    List<Failure> failures = result.getFailures();
    assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1);
    Failure failure = failures.get(0);
    String expectedMessage = "\n" + "Expected: (an instance of java.util.concurrent.TimeoutException and exception with message a string containing \"this is a message for FailsWithExpectedTimeoutButWrongError\")" + "\n" + "     " + "but: an instance of java.util.concurrent.TimeoutException <java.lang.NullPointerException> is a java.lang.NullPointerException";
    assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class).hasMessageContaining(expectedMessage);
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 59 with Failure

use of org.junit.runner.notification.Failure in project geode by apache.

the class RetryRuleLocalWithErrorTest method failsOnThirdAttempt.

@Test
public void failsOnThirdAttempt() {
    Result result = TestRunner.runTest(FailsOnThirdAttempt.class);
    assertThat(result.wasSuccessful()).isFalse();
    List<Failure> failures = result.getFailures();
    assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1);
    Failure failure = failures.get(0);
    assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class).hasMessage(FailsOnThirdAttempt.message);
    assertThat(FailsOnThirdAttempt.count).isEqualTo(3);
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 60 with Failure

use of org.junit.runner.notification.Failure in project geode by apache.

the class RetryRuleLocalWithExceptionTest method failsUnused.

@Test
public void failsUnused() {
    Result result = TestRunner.runTest(FailsUnused.class);
    assertThat(result.wasSuccessful()).isFalse();
    List<Failure> failures = result.getFailures();
    assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1);
    Failure failure = failures.get(0);
    assertThat(failure.getException()).isExactlyInstanceOf(CustomException.class).hasMessage(FailsUnused.message);
    assertThat(FailsUnused.count).isEqualTo(1);
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

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