KentBeck/junit — pull request #541 by Tibor17 (2012-11-09 17:19:31+00:00)
Title: Only @Category tests should be a subject to run in Categories runner

When only @ExcludeCategory is used on the suite and test case has a test without Category annotation, this test is executed.

It should not, which is mentioned in Categories Javadoc having sample code -only @Test should fail.

See our internal test:

CategoryTest#testCountOnAWithoutSlowTests()

There the test noCategory() should not be running. Thus getRunCount should return 1.

Result result = JUnitCore.runClasses(SomeAreSlowSuite.class);
assertEquals(2, result.getRunCount());

@RunWith(Categories.class)
@ExcludeCategory(Category1.class)
@SuiteClasses({SomeAreSlow.class})
public static class SomeAreSlowSuite {}

public static class SomeAreSlow {
@Test
public void noCategory() {
}

@Category(Category1.class)
@Test
public void justCategory1() {
}

@Category(Category2.class)
@Test
public void justCategory2() {
}

@Category({Category1.class, Category2.class})
@Test
public void both() {
}

@Category({Category2.class, Category1.class})
@Test
public void bothReversed() {
}
}