Skip to content
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

TestWatcher.testSkipped() should be invoked for tests not executed due to failures in @BeforeAll #4235

Open
1 task
joerg1985 opened this issue Jan 7, 2025 · 3 comments

Comments

@joerg1985
Copy link

joerg1985 commented Jan 7, 2025

I am using the TestWatcher to collect information for reporting the status of tests by implementing testDisabled, testSuccessful, testAborted, and testFailed. This is working fine as long as there is no failure inside a @BeforeAll or postProcessTestInstance method, in which case none of the TestWatcher methods is called, and the test is kind of lost.

To detect this state, a lot of other interfaces must be implemented, and information has to be combined. It would be better to have a complete view of the test results using only the TestWatcher.

Deliverables

  • TestWatcher.testSkipped(ExtensionContext context, ExtensionContext origin, Throwable reason) should be invoked for tests not executed at all
    • ExtensionContext origin argument with details about the failed ExtensionContext causing the test to get skipped
    • Throwable reason argument with details about the failure
@marcphilipp
Copy link
Member

You are referring to testDisabled, not testSkipped, right?

If so, this works as documented:

* <p>Please note that this API is currently only used to report the results of
* {@link org.junit.jupiter.api.Test @Test} methods and
* {@link org.junit.jupiter.api.TestTemplate @TestTemplate} methods (e.g.,
* {@code @RepeatedTest} and {@code @ParameterizedTest}). Moreover, if there is a
* failure at the class level &mdash; for example, an exception thrown by a
* {@code @BeforeAll} method &mdash; no test results will be reported. Similarly,
* if the test class is disabled via an {@link ExecutionCondition} &mdash; for
* example, {@code @Disabled} &mdash; no test results will be reported.

Have you considered registering a TestExecutionListener instead of using TestWatcher? It would receive a call to executionFinished with a failed result for the test class and you could then inspect its children via the TestPlan supplied to testPlanExecutionStarted.

@joerg1985
Copy link
Author

@marcphilipp i am not refering to testDisabled, the feature request is about a new method testSkipped (or better testBlocked?)
The way using the TestExecutionListener is possible and this is my current workaround, adding alot of complexity.

Implementing a TestWatcher is mutch easier and should - in my mind - cover all the states of all tests, otherwise people might miss some tests and they are e.g. not included into their reporting.

@sbrannen sbrannen changed the title TestWatcher.testSkipped to collect infos about not executed tests due to failures in @BeforeAll TestWatcher.testSkipped() should be invoked for tests not executed due to failures in @BeforeAll Jan 16, 2025
@marcphilipp
Copy link
Member

Team decision: Waiting for additional interest from the community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants