Search in sources :

Example 31 with Description

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

the class ParentRunner method getDescription.

//
// Implementation of Runner
//
@Override
public Description getDescription() {
    Class<?> clazz = getTestClass().getJavaClass();
    Description description;
    // to maintain backwards compatibility with JUnit 4.12
    if (clazz == null || !clazz.getName().equals(getName())) {
        description = Description.createSuiteDescription(getName(), getRunnerAnnotations());
    } else {
        description = Description.createSuiteDescription(clazz, getRunnerAnnotations());
    }
    for (T child : getFilteredChildren()) {
        description.addChild(describeChild(child));
    }
    return description;
}
Also used : Description(org.junit.runner.Description)

Example 32 with Description

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

the class EventCollector method hasSingleFailureWithMessage.

static Matcher<EventCollector> hasSingleFailureWithMessage(final Matcher<String> messageMatcher) {
    return new TypeSafeMatcher<EventCollector>() {

        @Override
        public boolean matchesSafely(EventCollector item) {
            return hasSingleFailure().matches(item) && messageMatcher.matches(item.fFailures.get(0).getMessage());
        }

        public void describeTo(org.hamcrest.Description description) {
            description.appendText("has single failure with message ");
            messageMatcher.describeTo(description);
        }

        @Override
        protected void describeMismatchSafely(EventCollector item, org.hamcrest.Description description) {
            description.appendText("was ");
            hasSingleFailure().describeMismatch(item, description);
            description.appendText(": ");
            boolean first = true;
            for (Failure f : item.fFailures) {
                if (!first) {
                    description.appendText(" ,");
                }
                description.appendText("'");
                description.appendText(f.getMessage());
                description.appendText("'");
                first = false;
            }
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure)

Example 33 with Description

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

the class EventCollector method failureIs.

static Matcher<EventCollector> failureIs(final Matcher<? super Throwable> exceptionMatcher) {
    return new TypeSafeMatcher<EventCollector>() {

        @Override
        public boolean matchesSafely(EventCollector item) {
            for (Failure f : item.fFailures) {
                return exceptionMatcher.matches(f.getException());
            }
            return false;
        }

        public void describeTo(org.hamcrest.Description description) {
            description.appendText("failure is ");
            exceptionMatcher.describeTo(description);
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure)

Example 34 with Description

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

the class ExternalResourceRuleTest method shouldThrowMultipleFailureExceptionWhenTestFailsAndClosingResourceFails.

@Test
public void shouldThrowMultipleFailureExceptionWhenTestFailsAndClosingResourceFails() throws Throwable {
    // given
    ExternalResource resourceRule = new ExternalResource() {

        @Override
        protected void after() {
            throw new RuntimeException("simulating resource tear down failure");
        }
    };
    Statement failingTest = new Fail(new RuntimeException("simulated test failure"));
    Description dummyDescription = Description.createTestDescription("dummy test class name", "dummy test name");
    try {
        resourceRule.apply(failingTest, dummyDescription).evaluate();
        fail("ExternalResource should throw");
    } catch (MultipleFailureException e) {
        assertThat(e.getMessage(), allOf(containsString("simulated test failure"), containsString("simulating resource tear down failure")));
    }
}
Also used : Description(org.junit.runner.Description) MultipleFailureException(org.junit.runners.model.MultipleFailureException) Statement(org.junit.runners.model.Statement) Fail(org.junit.internal.runners.statements.Fail) Test(org.junit.Test)

Example 35 with Description

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

the class ParameterizedTestTest method plansNamedCorrectly.

@Test
public void plansNamedCorrectly() throws Exception {
    Runner runner = Request.aClass(AdditionTest.class).getRunner();
    Description description = runner.getDescription();
    assertEquals("[2: 3 + 2 = 5]", description.getChildren().get(2).getDisplayName());
}
Also used : Runner(org.junit.runner.Runner) Description(org.junit.runner.Description) Test(org.junit.Test)

Aggregations

Description (org.junit.runner.Description)190 Test (org.junit.Test)84 Failure (org.junit.runner.notification.Failure)42 Result (org.junit.runner.Result)27 ArrayList (java.util.ArrayList)20 Request (org.junit.runner.Request)20 RunListener (org.junit.runner.notification.RunListener)20 JUnitCore (org.junit.runner.JUnitCore)16 IOException (java.io.IOException)14 Method (java.lang.reflect.Method)12 Filter (org.junit.runner.manipulation.Filter)12 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)10 Runner (org.junit.runner.Runner)9 RunNotifier (org.junit.runner.notification.RunNotifier)9 ComparisonFailure (org.junit.ComparisonFailure)8 Statement (org.junit.runners.model.Statement)8 InOrder (org.mockito.InOrder)8 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)7 Subscribe (com.google.common.eventbus.Subscribe)6 Step (gherkin.formatter.model.Step)6