Is it valid to use a non-static @RegisterExtension field when the extension implements BeforeAllCallback? #5562
-
|
Hi JUnit team! I'm a developer at JetBrains maintaining the JUnit plugin for IntelliJ IDEA. I'd like to get your input on a question that came up in our issue tracker. ContextIntelliJ IDEA warns when a non-static This is based on the
The ProblemWireMock's documentation describes non-static usage:
The pattern in question (simplified): class MyExtension implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) { }
}
class MyTest {
@RegisterExtension
MyExtension ext = new MyExtension(); // IntelliJ warns here
@Test
void test() { }
}QuestionIs this a valid usage pattern that IntelliJ should support, or should libraries like WireMock not recommend it? If it's not valid - please write a comment in IDEA-362874 confirming this. And we can open an issue in WireMock and similar libraries. IntelliJ can then keep the current warning. If it is valid - how should IDEs detect when to warn? We don't want to silently drop the warning for all extensions that implement |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
For completeness, do you have an example of an extension that should always be declared through a static field? I.e. is there a concrete example that prompted Intelij to implement a warning in the first place? |
Beta Was this translation helpful? Give feedback.
I think (1) is an improvement to the current situation. However, I think (2) would yield to many false-positives since there are extensions that are not intended to be used with fields at all.