Skip JUnit 5 TIA tests before constructing the test class #11178
Skip JUnit 5 TIA tests before constructing the test class #11178jbolsens-legion wants to merge 2 commits intoDataDog:masterfrom
Conversation
|
Hey @jbolsens-legion, thanks a lot for taking the time to contribute! As mentioned in the support ticket, my hesitation with the approach is that we would be moving away from JUnit's extension point of How viable would it be on your side to move the |
|
@daniel-mohedano thanks for finding that on junit side, I was not aware that this pattern is the norm. If this is the same pattern, I agree probably this PR should be closed, I will work to resolve issues in our own tests. |
What Does This Do
Moves the JUnit 5 TIA/ITR skip decision from Node.shouldBeSkipped to the earlier NodeTestTask.execute() hook, so that test classes for skipped methods are never constructed. Adds a regression test that asserts the skipped test class's constructor is not invoked.
Motivation
When Mockito.mockStatic(...) is used as a field-level initializer, allowing the class to be constructed before deciding to skip registers a static mock that is never closed (because @AfterEach doesn't run for skipped tests). The next test's field initializer then throws "static mocking is already registered in the current thread." Same pattern breaks any class-level resource whose teardown lives in @AfterEach.