JUnit malformed declaration
Reports JUnit test member declarations that are malformed and are likely not recognized by the JUnit test framework. The following problems are reported by this inspection:
Test classes that can't be constructed
Fields annotated by
@RegisterExtensionthat have the wrong type or are not declared as static when it is requiredStatic or private inner classes annotated with
@NestedParameterized tests that are defined without a source
Parameterized tests with a
@MethodSourcethat has an unknown, non-static or no-arg targetMismatched types between parameterized test method parameter and the specified
@ValueSourceor@EnumSourcevaluesTests that are annotated by more than one of
@Test,@ParameterizedTestor@RepeatedTestsetup()ortearDown()methods that are not public, whose return type is not void or take argumentssuite()methods that are private, take arguments or are not staticMethods annotated by
@BeforeClass,@AfterClass,@BeforeAllor@AfterAllthat are not public, not static, whose return type is not void or do not have a valid parameter listMethods annotated by
@Before,@After,@BeforeEachor@AfterEachthat are not public, whose return type is not void or take argumentsInjected
RepetitionInfoin@BeforeAllor@AfterAllmethodsInjected
RepetitionInfoin@BeforeEachor@AfterEachmethods that are used by@Testannotated testsFields and methods annotated by
@DataPointor@DataPointsthat are not public or not staticFields and methods annotated by
@Rulethat are not public or not a subtype ofTestRuleorMethodRuleFields and methods annotated by
@ClassRulethat are not public, not static or not a subtype ofTestRuleMethods inside a subclass of
TestCasewith atestprefix that are not public, whose return type is not void, take arguments or are staticMethods annotated by
@Testthat are not public, whose return type is not void, take arguments or are static
Note that in Kotlin, suspending functions do have arguments and a non-void return type. Therefore, they also will not be executed by the JUnit test runner. This inspection will also report about this problem.
Malformed @Before method example:
After the quick-fix is applied:
Missing method source example (Kotlin):
After the quick-fix is applied:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
JUnitMalformedDeclaration- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Use the inspection options to specify annotations. Any parameter annotated with one of these annotations will not be reported.
Inspection options
Here you can find the description of settings available for the JUnit malformed declaration inspection, and the reference of their default values.
- Ignore test parameter if it is annotated by
Default value:
[mockit.Mocked, org.junit.jupiter.api.io.TempDir]
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |