Competing Test Annotations
ID |
java.tests_method_annotated_competing_annot |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Java |
Tags |
reliability, testing |
Description
Reports a method carrying more than one of JUnit 5’s test-kind annotations — @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, @TestTemplate — at the same time.
Rationale
Exactly one of these annotations decides how the engine invokes a method: as a single run, as a fixed number of repetitions, as one invocation per supplied argument, and so on. Stacking a second one on top does not add behaviour, it conflicts with the first — the method runs more times than intended, or fails outright because the engine cannot resolve arguments the way the extra annotation implies. The usual cause is one annotation left behind after switching a test to another kind.
@Test
@RepeatedTest(3)
void recomputesTotalEachRun() {
// runs three times, but @Test also fires — behaviour depends on engine internals, not on intent
}