use of org.junit.platform.launcher.PostDiscoveryFilter in project junit5 by junit-team.
the class DefaultLauncherTests method prunesTestDescriptorsAfterApplyingPostDiscoveryFilters.
@Test
void prunesTestDescriptorsAfterApplyingPostDiscoveryFilters() {
TestEngineSpy engine = new TestEngineSpy() {
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
super.discover(discoveryRequest, uniqueId);
TestDescriptorStub engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
TestDescriptorStub containerDescriptor = new TestDescriptorStub(uniqueId.append("container", "a"), "container") {
@Override
public Type getType() {
return Type.CONTAINER;
}
};
containerDescriptor.addChild(new TestDescriptorStub(containerDescriptor.getUniqueId().append("test", "b"), "test"));
engineDescriptor.addChild(containerDescriptor);
return engineDescriptor;
}
};
DefaultLauncher launcher = createLauncher(engine);
TestPlan testPlan = launcher.discover(request().filters((PostDiscoveryFilter) testDescriptor -> FilterResult.includedIf(testDescriptor.isContainer())).build());
assertThat(testPlan.getRoots()).hasSize(1);
TestIdentifier engineIdentifier = getOnlyElement(testPlan.getRoots());
assertThat(testPlan.getChildren(engineIdentifier)).isEmpty();
}
use of org.junit.platform.launcher.PostDiscoveryFilter in project junit5 by junit-team.
the class DefaultLauncherTests method launcherAppliesPostDiscoveryFilters.
@Test
void launcherAppliesPostDiscoveryFilters() {
DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("myEngine");
DemoHierarchicalTestDescriptor test1 = engine.addTest("test1", noOp);
engine.addTest("test2", noOp);
DefaultLauncher launcher = createLauncher(engine);
PostDiscoveryFilter includeWithUniqueIdContainsTest = new PostDiscoveryFilterStub(descriptor -> FilterResult.includedIf(descriptor.getUniqueId().toString().contains("test")), () -> "filter1");
PostDiscoveryFilter includeWithUniqueIdContains1 = new PostDiscoveryFilterStub(descriptor -> FilterResult.includedIf(descriptor.getUniqueId().toString().contains("1")), () -> "filter2");
TestPlan testPlan = //
launcher.discover(//
request().selectors(//
selectPackage("any")).filters(includeWithUniqueIdContainsTest, //
includeWithUniqueIdContains1).build());
assertThat(testPlan.getChildren(UniqueId.forEngine("myEngine").toString())).hasSize(1);
assertThat(testPlan.getTestIdentifier(test1.getUniqueId().toString())).isNotNull();
}
use of org.junit.platform.launcher.PostDiscoveryFilter in project junit5 by junit-team.
the class DiscoveryRequestCreatorTests method convertsTagOptions.
@Test
void convertsTagOptions() {
options.setScanClasspath(true);
options.setIncludedTagExpressions(asList("fast", "medium", "slow"));
options.setExcludedTagExpressions(asList("slow"));
LauncherDiscoveryRequest request = convert();
List<PostDiscoveryFilter> postDiscoveryFilters = request.getPostDiscoveryFilters();
assertThat(postDiscoveryFilters).hasSize(2);
assertThat(postDiscoveryFilters.get(0).toString()).contains("TagFilter");
assertThat(postDiscoveryFilters.get(1).toString()).contains("TagFilter");
}
use of org.junit.platform.launcher.PostDiscoveryFilter in project junit5 by junit-team.
the class VintageLauncherIntegrationTests method executesAllTestsForNotFilterableChildRunnerOfSuite.
@TrackLogRecords
@Test
void executesAllTestsForNotFilterableChildRunnerOfSuite(LogRecordListener logRecordListener) {
Class<?> suiteClass = JUnit4SuiteOfSuiteWithFilterableChildRunner.class;
Class<?> testClass = JUnit4TestCaseWithNotFilterableRunner.class;
LauncherDiscoveryRequestBuilder request = //
request().selectors(//
selectClass(suiteClass)).filters((PostDiscoveryFilter) descriptor -> includedIf(descriptor.getDisplayName().contains("#1")));
TestPlan testPlan = discover(request);
logRecordListener.clear();
assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).hasSize(4);
Map<TestIdentifier, TestExecutionResult> results = execute(request);
//
assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactlyInAnyOrder("JUnit Vintage", suiteClass.getName(), testClass.getName(), "Test #0", "Test #1");
//
assertThat(logRecordListener.stream(RunnerTestDescriptor.class, Level.WARNING).map(LogRecord::getMessage)).containsExactly(//
"Runner " + Suite.class.getName() + " (used on class " + suiteClass.getName() + ")" + " was not able to satisfy all filter requests.");
}
use of org.junit.platform.launcher.PostDiscoveryFilter in project junit5 by junit-team.
the class VintageLauncherIntegrationTests method filtersOutAllDescendantsOfParameterizedTestCase.
@Test
void filtersOutAllDescendantsOfParameterizedTestCase() {
Class<?> testClass = ParameterizedTestCase.class;
LauncherDiscoveryRequestBuilder request = //
request().selectors(//
selectClass(testClass)).filters((PostDiscoveryFilter) descriptor -> excluded("excluded"));
TestPlan testPlan = discover(request);
assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).isEmpty();
Map<TestIdentifier, TestExecutionResult> results = execute(request);
//
assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactly("JUnit Vintage");
}
Aggregations