Skip to content

Commit 02a8720

Browse files
committed
Allow TestEngines to be completely dynamic
Prior to this commit, it was impossible to create a custom TestEngine that was completely dynamic in nature (i.e., that did not discover any tests during the discovery phase) since such an engine would get pruned from the test plan. This commit addresses this issue by ensuring that engines without statically registered children are not pruned by the Launcher. Closes: #367
1 parent 8b77b6f commit 02a8720

File tree

3 files changed

+3
-54
lines changed

3 files changed

+3
-54
lines changed

junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/Root.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ void applyPostDiscoveryFilters(LauncherDiscoveryRequest discoveryRequest) {
7171
* that do not have executable tests.
7272
*
7373
* <p>If a {@link TestEngine} ends up with no {@code TestDescriptors} after
74-
* pruning, it will be removed.
74+
* pruning, it will <strong>not</strong> be removed.
7575
*/
7676
void prune() {
7777
acceptInAllTestEngines(REMOVE_DESCRIPTORS_WITHOUT_TESTS);
78-
pruneEmptyTestEngines();
7978
}
8079

8180
private boolean isExcluded(TestDescriptor descriptor, Filter<TestDescriptor> postDiscoveryFilter) {
@@ -86,8 +85,4 @@ private void acceptInAllTestEngines(TestDescriptor.Visitor visitor) {
8685
this.testEngineDescriptors.values().forEach(descriptor -> descriptor.accept(visitor));
8786
}
8887

89-
private void pruneEmptyTestEngines() {
90-
this.testEngineDescriptors.values().removeIf(descriptor -> descriptor.getChildren().isEmpty());
91-
}
92-
9388
}

platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherTests.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.junit.platform.engine.test.TestEngineSpy;
3636
import org.junit.platform.launcher.PostDiscoveryFilter;
3737
import org.junit.platform.launcher.PostDiscoveryFilterStub;
38-
import org.junit.platform.launcher.TagFilter;
3938
import org.junit.platform.launcher.TestIdentifier;
4039
import org.junit.platform.launcher.TestPlan;
4140

@@ -71,7 +70,7 @@ void discoverEmptyTestPlanWithEngineWithoutAnyTests() {
7170

7271
TestPlan testPlan = launcher.discover(request().build());
7372

74-
assertThat(testPlan.getRoots()).isEmpty();
73+
assertThat(testPlan.getRoots()).hasSize(1);
7574
}
7675

7776
@Test
@@ -288,19 +287,4 @@ void withoutConfigurationParameters_LookupFallsBackToSystemProperty() {
288287
}
289288
}
290289

291-
@Test
292-
void engineDescriptorsWithoutAnyChildrenAreNotFilteredButPruned() {
293-
DefaultLauncher launcher = createLauncher(new DummyTestEngine("emptyEngine"));
294-
295-
// @formatter:off
296-
TestPlan testPlan = launcher.discover(
297-
request()
298-
.selectors(selectPackage("any"))
299-
.filters(TagFilter.includeTags("foo"))
300-
.build());
301-
// @formatter:on
302-
303-
assertThat(testPlan.getRoots()).isEmpty();
304-
}
305-
306290
}

platform-tests/src/test/java/org/junit/platform/runner/JUnitPlatformRunnerTests.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,7 @@ public String getId() {
418418

419419
@Override
420420
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
421-
EngineDescriptor engineDescriptor = new EngineDescriptor(uniqueId, "Dynamic Engine");
422-
423-
// If we don't add this pseudo-container, the whole engine will get pruned because
424-
// it otherwise won't have any (static) children.
425-
TestDescriptor dynamicTestContainer = new DynamicTestContainerTestDescriptor(
426-
uniqueId.append("pseudo-container", "0"), "dynamic test pseudo-container");
427-
engineDescriptor.addChild(dynamicTestContainer);
428-
429-
return engineDescriptor;
421+
return new EngineDescriptor(uniqueId, "Dynamic Engine");
430422
}
431423

432424
@Override
@@ -462,28 +454,6 @@ public void execute(ExecutionRequest request) {
462454

463455
}
464456

465-
private static class DynamicTestContainerTestDescriptor extends AbstractTestDescriptor {
466-
467-
DynamicTestContainerTestDescriptor(UniqueId uniqueId, String displayName) {
468-
super(uniqueId, displayName);
469-
}
470-
471-
@Override
472-
public boolean isContainer() {
473-
return true;
474-
}
475-
476-
@Override
477-
public boolean isTest() {
478-
return false;
479-
}
480-
481-
@Override
482-
public boolean hasTests() {
483-
return true;
484-
}
485-
}
486-
487457
private static class DemoContainerTestDescriptor extends AbstractTestDescriptor {
488458

489459
DemoContainerTestDescriptor(UniqueId uniqueId, String displayName) {

0 commit comments

Comments
 (0)