Skip to content

Commit 38155c8

Browse files
committed
Allow disabling discovery issues reported by the Vintage engine (#5049)
Whether the Vintage engine should report discovery issues such as deprecation notices is now configurable via the new `junit.vintage.discovery.issue.reporting.enabled` configuration parameter. Resolves #5030. (cherry picked from commit 4041234)
1 parent 522ac84 commit 38155c8

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-6.0.1.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ repository on GitHub.
6464
[[release-notes-6.0.1-junit-vintage-new-features-and-improvements]]
6565
==== New Features and Improvements
6666

67-
* ❓
67+
* Allow disabling the reporting of discovery issues by the JUnit Vintage engine (including
68+
the one reported for its deprecation) by setting the new
69+
`junit.vintage.discovery.issue.reporting.enabled` configuration parameter to `false`.

documentation/src/docs/asciidoc/user-guide/migration-from-junit4.adoc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@ classpath does not lead to any conflicts. It is therefore safe to maintain exist
1919
[[migrating-from-junit4-running]]
2020
=== Running JUnit 4 Tests on the JUnit Platform
2121

22-
WARNING: The JUnit Vintage engine is deprecated and should only be used temporarily while
22+
[WARNING]
23+
====
24+
The JUnit Vintage engine is deprecated and should only be used temporarily while
2325
migrating tests to JUnit Jupiter or another testing framework with native JUnit Platform
2426
support.
2527
28+
By default, if the JUnit Vintage engine is registered and discovers at least one test
29+
class, it reports a <<running-tests-discovery-issues, discovery issue>> of INFO severity.
30+
You can prevent this discovery issue from being reported by setting the
31+
`junit.vintage.discovery.issue.reporting.enabled`
32+
<<running-tests-config-params, configuration parameter>> to `false`.
33+
====
34+
2635
Make sure that the `junit-vintage-engine` artifact is in your test runtime path. In that
2736
case JUnit 3 and JUnit 4 tests will automatically be picked up by the JUnit Platform
2837
launcher.

junit-vintage-engine/src/main/java/org/junit/vintage/engine/Constants.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ public final class Constants {
7272
@API(status = MAINTAINED, since = "5.13.3")
7373
public static final String PARALLEL_METHOD_EXECUTION = "junit.vintage.execution.parallel.methods";
7474

75+
/**
76+
* Property name used to configure whether the JUnit Vintage engine should
77+
* report discovery issues such as deprecation notices.
78+
*
79+
* <p>Set this property to {@code false} to disable reporting of discovery
80+
* issues. Defaults to {@code true}.
81+
*
82+
* @since 6.0.1
83+
*/
84+
@API(status = MAINTAINED, since = "6.0.1")
85+
public static final String DISCOVERY_ISSUE_REPORTING_ENABLED_PROPERTY_NAME = "junit.vintage.discovery.issue.reporting.enabled";
86+
7587
private Constants() {
7688
/* no-op */
7789
}

junit-vintage-engine/src/main/java/org/junit/vintage/engine/discovery/VintageDiscoverer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.junit.platform.engine.TestDescriptor;
2020
import org.junit.platform.engine.UniqueId;
2121
import org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver;
22+
import org.junit.vintage.engine.Constants;
2223
import org.junit.vintage.engine.descriptor.RunnerTestDescriptor;
2324
import org.junit.vintage.engine.descriptor.VintageEngineDescriptor;
2425

@@ -46,7 +47,7 @@ public VintageEngineDescriptor discover(EngineDiscoveryRequest discoveryRequest,
4647
RunnerTestDescriptor runnerTestDescriptor = (RunnerTestDescriptor) testDescriptor;
4748
postProcessor.applyFiltersAndCreateDescendants(runnerTestDescriptor);
4849
}
49-
if (!engineDescriptor.getChildren().isEmpty()) {
50+
if (isDiscoveryIssueReportingEnabled(discoveryRequest) && !engineDescriptor.getChildren().isEmpty()) {
5051
var issue = DiscoveryIssue.create(DiscoveryIssue.Severity.INFO, //
5152
"The JUnit Vintage engine is deprecated and should only be " //
5253
+ "used temporarily while migrating tests to JUnit Jupiter or another testing " //
@@ -56,4 +57,11 @@ public VintageEngineDescriptor discover(EngineDiscoveryRequest discoveryRequest,
5657
return engineDescriptor;
5758
}
5859

60+
@SuppressWarnings("deprecation")
61+
private static boolean isDiscoveryIssueReportingEnabled(EngineDiscoveryRequest discoveryRequest) {
62+
return discoveryRequest.getConfigurationParameters() //
63+
.getBoolean(Constants.DISCOVERY_ISSUE_REPORTING_ENABLED_PROPERTY_NAME) //
64+
.orElse(true);
65+
}
66+
5967
}

junit-vintage-engine/src/test/java/org/junit/vintage/engine/VintageTestEngineDiscoveryTests.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ void reportsNoDiscoveryIssuesWhenNoTestsAreFound() {
713713
}
714714

715715
@Test
716-
void reportDiscoveryIssueWhenTestsAreFound() {
716+
void reportDiscoveryIssueWhenTestsAreFoundByDefault() {
717717
var request = discoveryRequestForClass(PlainJUnit4TestCaseWithSingleTestWhichFails.class);
718718

719719
var results = discover(request);
@@ -725,6 +725,18 @@ void reportDiscoveryIssueWhenTestsAreFound() {
725725
assertThat(issue.message()).contains("JUnit Vintage engine is deprecated");
726726
}
727727

728+
@SuppressWarnings("deprecation")
729+
@Test
730+
void reportNoDiscoveryIssueWhenTestsAreFoundButConfigurationParameterIsSet() {
731+
var request = request() //
732+
.selectors(selectClass(PlainJUnit4TestCaseWithSingleTestWhichFails.class)) //
733+
.configurationParameter(Constants.DISCOVERY_ISSUE_REPORTING_ENABLED_PROPERTY_NAME, "false").build();
734+
735+
var results = discover(request);
736+
737+
assertThat(results.getDiscoveryIssues()).isEmpty();
738+
}
739+
728740
private TestDescriptor findChildByDisplayName(TestDescriptor runnerDescriptor, String displayName) {
729741
// @formatter:off
730742
var children = runnerDescriptor.getChildren();

0 commit comments

Comments
 (0)