Search in sources :

Example 66 with Failure

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

the class RetryRuleGlobalWithErrorTest method failsOnSecondAttempt.

@Test
public void failsOnSecondAttempt() {
    Result result = TestRunner.runTest(FailsOnSecondAttempt.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(FailsOnSecondAttempt.message);
    assertThat(FailsOnSecondAttempt.count).isEqualTo(2);
}
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 67 with Failure

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

the class ExpectedTimeoutRuleTest method failsWithoutExpectedException.

@Test
public void failsWithoutExpectedException() {
    Result result = TestRunner.runTest(FailsWithoutExpectedException.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("Expected test to throw an instance of " + TimeoutException.class.getName());
}
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 68 with Failure

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

the class IgnoreUntilRuleTest method shouldExecuteWhenUntilIsDefault.

@Test
public void shouldExecuteWhenUntilIsDefault() {
    Result result = TestRunner.runTest(ShouldExecuteWhenUntilIsDefault.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(ASSERTION_ERROR_MESSAGE);
    assertThat(ShouldExecuteWhenUntilIsDefault.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)

Example 69 with Failure

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

the class RepeatRuleTest method failingTestShouldFailOneTimeWhenRepeatIsUnused.

@Test
public void failingTestShouldFailOneTimeWhenRepeatIsUnused() {
    Result result = TestRunner.runTest(FailingTestShouldFailOneTimeWhenRepeatIsUnused.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(ASSERTION_ERROR_MESSAGE);
    assertThat(FailingTestShouldFailOneTimeWhenRepeatIsUnused.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)

Example 70 with Failure

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

the class ModelTestSuite method runChild.

@Override
protected void runChild(Test child, RunNotifier notifier) {
    Method setUp = null;
    try {
        setUp = child.getClass().getMethod("setUp");
    } catch (SecurityException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        throw new RuntimeException(e1);
    } catch (NoSuchMethodException e1) {
    }
    Method tearDown = null;
    try {
        tearDown = child.getClass().getMethod("tearDown");
    } catch (SecurityException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        throw new RuntimeException(e1);
    } catch (NoSuchMethodException e1) {
    }
    for (Method m : child.getClass().getMethods()) {
        if (m.getName().startsWith("test") && m.getParameterTypes().length == 0) {
            Description desc = Description.createTestDescription(child.getClass(), child.toString());
            notifier.fireTestStarted(desc);
            try {
                if (setUp != null) {
                    setUp.invoke(child);
                }
                m.invoke(child);
                if (tearDown != null) {
                    tearDown.invoke(child);
                }
                notifier.fireTestFinished(desc);
            } catch (IllegalArgumentException e) {
                notifier.fireTestFailure(new Failure(desc, e));
            } catch (IllegalAccessException e) {
                notifier.fireTestFailure(new Failure(desc, e));
            } catch (InvocationTargetException e) {
                notifier.fireTestFailure(new Failure(desc, e.getTargetException()));
            } catch (RuntimeException e) {
                notifier.fireTestFailure(new Failure(desc, e));
                throw e;
            }
        }
    }
}
Also used : Description(org.junit.runner.Description) Method(java.lang.reflect.Method) Failure(org.junit.runner.notification.Failure) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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