-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Draft API for reporting discovery issues #4380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| default void selectorProcessed(UniqueId engineId, DiscoverySelector selector, SelectorResolutionResult result) { | ||
| } | ||
|
|
||
| default void issueFound(UniqueId engineId, EngineDiscoveryIssue issue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 This is the top-level API for engines to report discovery issues.
| Set<Severity> failureIssueSeverities = Arrays.stream(configValue.split(",")) // | ||
| .map(Severity::valueOf) // TODO case-insensitive parsing | ||
| .collect(toCollection(() -> EnumSet.noneOf(Severity.class))); | ||
| // TODO Collect errors and throw exception or log all issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 The idea here is that the default abortOnFailure listener would treat the configured issue severities as failures and throw an exception containing all of them after the launcher has finished test discovery. In 5.13 the list would be empty (?) but in 6.0 we could make it strict and fail on deprecations and warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, a discovery listener could collect all issues and report the engine descriptor as failed during execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #4380 (comment)
| context.reportIssue(EngineDiscoveryIssue.builder(Severity.NOTICE, message) // | ||
| .selector(selector) // | ||
| .source(MethodSource.from(testClass, method))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Engines using the EngineDiscoveryRequestResolver framework work discovery can report issues via the Context passed to each SelectorResolver.
| .addTestDescriptorVisitor(ctx -> new MethodOrderingVisitor(getConfiguration(ctx))) // | ||
| .addTestDescriptorVisitor(ctx -> new ClassOrderingVisitor(ctx.getIssueReporter(), getConfiguration(ctx))) // | ||
| .addTestDescriptorVisitor(ctx -> new MethodOrderingVisitor(ctx.getIssueReporter(), getConfiguration(ctx))) // | ||
| .addTestDescriptorVisitor(ctx -> new ValidatingVisitor(ctx.getIssueReporter())) // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Visitors registered via EngineDiscoveryRequestResolver can use the DiscoveryIssueReporter to report issues.
| if (descriptor instanceof Validatable) { | ||
| ((Validatable) descriptor).validate(new Reporter(descriptor)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Engines such as Jupiter can use any custom logic to validate during discovery. Here a visitor is used that checks for the Jupiter-specific Validatable marker interface.
| afterAllMethods.stream() // | ||
| .filter(ModifierSupport::isPrivate) // | ||
| .forEach(method -> reporter.reportIssue(Severity.DEPRECATION, | ||
| String.format("@AfterAll method [%s] should not be private.", method.toGenericString()), | ||
| b -> b.source(MethodSource.from(method)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Example of a engine-specific "post-discovery" validation that reports private lifecycle methods as deprecated (also would need to be done for @BeforeEach etc.).
| AbstractOrderingVisitor.this.issueReporter // | ||
| .reportIssue(EngineDiscoveryIssue.builder(Severity.WARNING, message) // | ||
| .source(parentTestDescriptor.getSource())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Another example of a custom "post-discovery" validation that reports a warning for issues during class/method ordering.
07b8259 to
f848139
Compare
junit-platform-engine/src/main/java/org/junit/platform/engine/EngineDiscoveryIssue.java
Outdated
Show resolved
Hide resolved
f848139 to
7827335
Compare
leonard84
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some preliminary comments
junit-platform-engine/src/main/java/org/junit/platform/engine/EngineDiscoveryIssue.java
Outdated
Show resolved
Hide resolved
|
|
||
| void validate(IssueReporter issueReporter); | ||
|
|
||
| interface IssueReporter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚲🏠 Why did you choose issue instead of problem?
...n/java/org/junit/platform/launcher/listeners/discovery/LoggingLauncherDiscoveryListener.java
Show resolved
Hide resolved
mpkorstanje
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very workable. It would cover all use cases Cucumber has for it now.
6f121de to
09ddba0
Compare
|
Was this just for testing, or will deprecations fail the discovery? IMHO, only |
That was just for testing. We haven't yet decided what severity would fail the build, and that may differ in 5.x and 6.0. We also plan to make it configurable. |
|
Correct, that was just for testing. All "non-critical" issues (depending on the severity configured as "critical") will just be logged. |
- Rename to `DiscoveryIssue` - Remove `selector()` property - Add `ERROR` severity - Rename listener method to `issueEncountered`
Since those are now reported as discovery issues
It expects engine descriptors to be containers
08b24e0 to
a89235c
Compare
|
Superseded by #4385 |






Overview
This is a proof-of-concept draft for #242 to get early feedback on the API.
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations