@Test public void testCountWithExplicitFilter() throws Throwable { CategoryFilter include = CategoryFilter.include(SlowTests.class); Request baseRequest = Request.aClass(TestSuiteWithNoCategories.class); Result result = new JUnitCore().run(baseRequest.filterWith(include)); assertTrue(result.wasSuccessful()); assertEquals(2, result.getRunCount()); }
@Test public void categoryFilterLeavesOnlyMatchingMethods() throws InitializationError, NoTestsRemainException { CategoryFilter filter = CategoryFilter.include(SlowTests.class); BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(A.class); filter.apply(runner); assertEquals(1, runner.testCount()); }
@Test public void categoryFilterRejectsIncompatibleCategory() throws InitializationError, NoTestsRemainException { CategoryFilter filter = CategoryFilter.include(SlowTests.class); BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner( OneFastOneSlow.class); filter.apply(runner); assertEquals(1, runner.testCount()); }
@Test public void describeMultipleCategoryFilter() { CategoryFilter filter= CategoryFilter.include(FastTests.class, SlowTests.class); String d1= format("categories [%s, %s]", FastTests.class, SlowTests.class); String d2= format("categories [%s, %s]", SlowTests.class, FastTests.class); assertThat(filter.describe(), is(anyOf(equalTo(d1), equalTo(d2)))); }
@Test @SuppressWarnings("unchecked") public void testCountWithMultipleExcludeFilter() throws Throwable { Set<Class<?>> exclusions= new HashSet<Class<?>>(2); Collections.addAll(exclusions, SlowTests.class, FastTests.class); CategoryFilter exclude = CategoryFilter.categoryFilter(true, null, true, exclusions); Request baseRequest= Request.aClass(OneOfEach.class); Result result= new JUnitCore().run(baseRequest.filterWith(exclude)); assertTrue(result.wasSuccessful()); assertEquals(1, result.getRunCount()); }
@Test public void testCountWithMultipleIncludeFilter() throws Throwable { CategoryFilter exclude = CategoryFilter.include(true, SlowTests.class, FastTests.class); Request baseRequest= Request.aClass(OneOfEach.class); Result result= new JUnitCore().run(baseRequest.filterWith(exclude)); assertTrue(result.wasSuccessful()); assertEquals(2, result.getRunCount()); }
@Test public void beforeClassShouldNotRunWhenAllTestsAreFiltered() { Result result = new JUnitCore().run(Request.classes( BeforeClassWithFilteredTest.class, HasUnfilteredTest.class) .filterWith(CategoryFilter.exclude(FilteredTests.class))); analyseResult( result, "BeforeClass should not have been executed because the test method is filtered!"); }
@Test public void describeACategoryFilter() { CategoryFilter filter = CategoryFilter.include(SlowTests.class); assertEquals("categories [" + SlowTests.class + "]", filter.describe()); }
@Test public void describeACategoryFilter() { CategoryFilter filter = CategoryFilter.include(SlowTests.class); assertEquals("category " + SlowTests.class, filter.describe()); }