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;
}
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;
}
}
};
}
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);
}
};
}
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")));
}
}
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());
}
Aggregations