KentBeck/junit — pull request #361 by stefanbirkner (2011-11-10 00:24:02+00:00)
Title: Created JUnitSelfTestRunner

JUnitSelfTestRunner is the test runner for declarative tests of JUnit
itself. It runs your test classes and verifies the JUnit events
(failure, test started, ...) according to your specification.

A test class using this runner has several static inner classes, which
are annotated with @JUnitSelfTest. Every such class is a single test and
the test specification is provided by a hamcrest matcher, which is an
additional field annotated with @ExpectedEvents. The
EventCollectorMatchers class provides some matchers.

Here is an example of a test class with two tests.

@RunWith(JUnitSelfTestRunner.class)
public class MySelfTests {
@JUnitSelfTest
public static class FirstSelfTest {
@ExpectedEvents
public static final Matcher EXPECTED_EVENTS
= onlySuccessfulTests();

@Test
public void successfulTest() {
assertTrue(true);
}
}

@JUnitSelfTest
public static class SecondSelfTest {
@ExpectedEvents
public static final Matcher EXPECTED_EVENTS
= numberOfFailures(1);

@Test
public void successfulTest() {
assertTrue(true);
}

@Test
public void failingTest() {
fail();
}
}
}