Skip to content

Commit a1933f2

Browse files
committed
Document discovery issue reporting
Issue: #242
1 parent 6c90fb9 commit a1933f2

File tree

4 files changed

+92
-4
lines changed

4 files changed

+92
-4
lines changed

documentation/src/docs/asciidoc/link-attributes.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ endif::[]
2525
:ClasspathResourceSelector: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/ClasspathResourceSelector.html[ClasspathResourceSelector]
2626
:ClasspathRootSelector: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/ClasspathRootSelector.html[ClasspathRootSelector]
2727
:ClassSelector: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/ClassSelector.html[ClassSelector]
28+
:DiscoveryIssue: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/DiscoveryIssue.html[DiscoveryIssue]
29+
:DiscoveryIssueReporter: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/support/discovery/DiscoveryIssueReporter.html[DiscoveryIssueReporter]
2830
:DirectorySelector: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/DirectorySelector.html[DirectorySelector]
2931
:DiscoverySelectors: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/DiscoverySelectors.html[DiscoverySelectors]
3032
:DiscoverySelectors_selectClasspathResource: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/DiscoverySelectors.html#selectClasspathResource(java.lang.String)[selectClasspathResource]
@@ -40,6 +42,7 @@ endif::[]
4042
:DiscoverySelectors_selectPackage: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/DiscoverySelectors.html#selectPackage(java.lang.String)[selectPackage]
4143
:DiscoverySelectors_selectUniqueId: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/DiscoverySelectors.html#selectUniqueId(java.lang.String)[selectUniqueId]
4244
:DiscoverySelectors_selectUri: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/DiscoverySelectors.html#selectUri(java.lang.String)[selectUri]
45+
:EngineDiscoveryListener: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/EngineDiscoveryListener.html[EngineDiscoveryListener]
4346
:EngineDiscoveryRequest: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/EngineDiscoveryRequest.html[EngineDiscoveryRequest]
4447
:FileSelector: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/discovery/FileSelector.html[FileSelector]
4548
:HierarchicalTestEngine: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/support/hierarchical/HierarchicalTestEngine.html[HierarchicalTestEngine]
@@ -57,6 +60,7 @@ endif::[]
5760
:TestEngine: {javadoc-root}/org.junit.platform.engine/org/junit/platform/engine/TestEngine.html[TestEngine]
5861
// Platform Launcher API
5962
:junit-platform-launcher: {javadoc-root}/org.junit.platform.launcher/org/junit/platform/launcher/package-summary.html[junit-platform-launcher]
63+
:DiscoveryIssueException: {javadoc-root}/org.junit.platform.launcher/org/junit/platform/launcher/core/DiscoveryIssueException.html[DiscoveryIssueException]
6064
:Launcher: {javadoc-root}/org.junit.platform.launcher/org/junit/platform/launcher/Launcher.html[Launcher]
6165
:LauncherConfig: {javadoc-root}/org.junit.platform.launcher/org/junit/platform/launcher/core/LauncherConfig.html[LauncherConfig]
6266
:LauncherDiscoveryListener: {javadoc-root}/org.junit.platform.launcher/org/junit/platform/launcher/LauncherDiscoveryListener.html[LauncherDiscoveryListener]

documentation/src/docs/asciidoc/release-notes/release-notes-5.13.0-M3.adoc

+32-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ repository on GitHub.
3535
and
3636
<<../user-guide/index.adoc#launcher-api-managing-state-across-test-engines, request-scoped>>
3737
resources.
38+
* Introduce a mechanism for `TestEngine` implementations to report issues encountered
39+
during test discovery. If an engine reports a `DiscoveryIssue` with a `Severity` equal
40+
to or higher than a configurable critical severity, its tests will not be executed.
41+
Instead, the engine will be reported as failed during execution with a failure message
42+
listing all critical issues. Non-critical issues will be logged but will not prevent the
43+
engine from executing its tests. The critical severity can be configured via a new
44+
configuration parameter and, currently, defaults to `ERROR`. Please refer to the
45+
<<../user-guide/index.adoc#running-tests-discovery-issues, User Guide>> for details.
46+
+
47+
If you're a test engine maintainer, please see the
48+
<<../user-guide/index.adoc#test-engines-discovery-issues, User Guide>> for details on how
49+
to start reporting discovery issues.
50+
* Start reporting discovery issues for problematic `@Suite` classes:
51+
- Invalid `@Suite` class declarations (for example, when `private`)
52+
- Invalid `@BeforeSuite`/`@AfterSuite` method declarations (for example, when not
53+
`static`)
54+
- Cyclic dependencies between `@Suite` classes
3855

3956

4057
[[release-notes-5.13.0-M3-junit-jupiter]]
@@ -53,10 +70,21 @@ repository on GitHub.
5370
[[release-notes-5.13.0-M3-junit-jupiter-new-features-and-improvements]]
5471
==== New Features and Improvements
5572

56-
* Return types of `@TestFactory` methods are now validated during discovery rather than
57-
during execution. Invalid `@TestFactory` methods are no longer executed but reported as
58-
discovery issues for consistency with how `@Test` and `@TestTemplate` methods are
59-
handled.
73+
* Start reporting discovery issues for potentially problematic test classes:
74+
- Invalid `@Test` and `@TestTemplate` method declarations (for example, when return
75+
type is not `void`)
76+
- Invalid `@TestFactory` methods (for example, when return type is invalid)
77+
- Multiple method-level annotations (for example, `@Test` and `@TestTemplate`)
78+
- Invalid test class and `@Nested` class declarations (for example, `static` `@Nested`
79+
classes)
80+
- Potentially missing `@Nested` annotations (for example, non-abstract inner classes
81+
that contain test methods)
82+
- Invalid lifecycle method declarations (for example, when `private`)
83+
- Invalid `@Tag` syntax
84+
- Blank `@DisplayName` declarations
85+
- Blank `@SentenceFragment` declarations
86+
- `@BeforeParameterizedClassInvocation` and `@AfterParameterizedClassInvocation`
87+
methods declared in non-parameterized test classes
6088

6189

6290
[[release-notes-5.13.0-M3-junit-vintage]]

documentation/src/docs/asciidoc/user-guide/advanced-topics/engines.adoc

+19
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,22 @@ compatibility with build tools and IDEs:
120120
siblings or other nodes that are required for the execution of the selected tests.
121121
* `TestEngines` _should_ support <<running-tests-tags, tagging>> tests and containers so
122122
that tag filters can be applied when discovering tests.
123+
124+
[[test-engines-discovery-issues]]
125+
==== Reporting Discovery Issues
126+
127+
Test engines should report <<running-tests-discovery-issues, discovery issues>> if they
128+
encounter any problems or potential misconfigurations during test discovery. This is
129+
especially important if the issue could lead to tests not being executed at all or only
130+
partially.
131+
132+
In order to report a `{DiscoveryIssue}`, a test engine should call the
133+
`issueEncountered()` method on the `{EngineDiscoveryListener}` available via the
134+
`{EngineDiscoveryRequest}` passed to its `discover()` method. Rather than passing the
135+
listener around, the `{DiscoveryIssueReporter}` interface should be used. It also provides
136+
a way to create a `Condition` that reports a discovery issue if its check fails and may
137+
be used as a `Predicate` or `Consumer`. Please refer to the implementations of the
138+
<<test-engines-junit, test engines provided by JUnit>> for examples.
139+
140+
Moreover, <<testkit-engine-discovery, Engine Test Kit>> provides a way to write tests for
141+
reported discovery issues.

documentation/src/docs/asciidoc/user-guide/running-tests.adoc

+37
Original file line numberDiff line numberDiff line change
@@ -1288,3 +1288,40 @@ never be excluded.
12881288

12891289
In addition, all elements prior to and including the first call from the JUnit Platform
12901290
Launcher will be removed.
1291+
1292+
[[running-tests-discovery-issues]]
1293+
=== Discovery Issues
1294+
1295+
Test engines may encounter issues during test discovery. For example, the declaration of a
1296+
test class or method may be invalid. To avoid such issues from going unnoticed, the JUnit
1297+
Platform provides a <<test-engines-discovery-issues, mechanism for test engines>> to
1298+
report them with different severity levels:
1299+
1300+
INFO::
1301+
Indicates that the engine encountered something that could be potentially problematic, but
1302+
could also happen due to a valid setup or configuration.
1303+
1304+
WARNING::
1305+
Indicates that the engine encountered something that is problematic and might lead to
1306+
unexpected behavior or will be removed or changed in a future release.
1307+
1308+
ERROR::
1309+
Indicates that the engine encountered something that is definitely problematic and will
1310+
lead to unexpected behavior.
1311+
1312+
If an engine reports an issue with a severity equal to or higher than a configurable
1313+
_critical_ severity, its tests will not be executed. Instead, the engine will be reported
1314+
as failed during execution with a `{DiscoveryIssueException}` listing all critical issues.
1315+
Non-critical issues will be logged but will not prevent the engine from executing its
1316+
tests. The `junit.platform.discovery.issue.severity.critical`
1317+
<<running-tests-config-params, configuration parameter>> can be used to set the critical
1318+
severity level. Currently, the default value is `ERROR` but it may be changed in a future
1319+
release.
1320+
1321+
TIP: To surface all discovery issues in your project, it is recommended to set the
1322+
`junit.platform.discovery.issue.severity.critical` configuration parameter to `INFO`.
1323+
1324+
In addition, registered `{LauncherDiscoveryListener}` implementations can receive
1325+
discovery issues via the `issueEncountered()` method. This allows IDEs and build tools to
1326+
report issues to the user in a more user-friendly way. For example, IDEs may choose to
1327+
display all issues in a list or table.

0 commit comments

Comments
 (0)