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());
}
use of org.junit.runner.Description in project junit4 by junit-team.
the class ParentRunnerFilteringTest method testCountClassFiltering.
@Test
public void testCountClassFiltering() throws Exception {
JUnitCore junitCore = new JUnitCore();
Request request = Request.aClass(ExampleTest.class);
CountingFilter countingFilter = new CountingFilter();
Request requestFiltered = request.filterWith(countingFilter);
Result result = junitCore.run(requestFiltered);
assertEquals(1, result.getRunCount());
assertEquals(0, result.getFailureCount());
Description desc = createTestDescription(ExampleTest.class, "test1");
assertEquals(1, countingFilter.getCount(desc));
}
use of org.junit.runner.Description in project junit4 by junit-team.
the class ListenerTest method notifyListenersInTheOrderInWhichTheyAreAdded.
@Test
public void notifyListenersInTheOrderInWhichTheyAreAdded() {
JUnitCore core = new JUnitCore();
log = "";
core.addListener(new RunListener() {
@Override
public void testRunStarted(Description description) throws Exception {
log += "first ";
}
});
core.addListener(new RunListener() {
@Override
public void testRunStarted(Description description) throws Exception {
log += "second ";
}
});
core.run(OneTest.class);
assertEquals("first second ", log);
}
Aggregations