Several test methods of a class are the same code with different literals, which one parameterized test would cover
What it finds
Three tests that differ only in their numbers and strings repeat one test three times. A parameterized test lists the cases as data and keeps one body to maintain.
Reported is every test method after the second whose body has the same tokens as two others in its class, apart from the values of literals.
From the rule's source, repeated_test_shape.rs.
class ShapeTest { @Test void one() { assertEquals(1, parse("1")); } @Test void two() { assertEquals(2, parse("2")); } @Test void three() {tx0 reports: repeats the code of others assertEquals(3, parse("3")); } int parse(String s) { return 0; } void assertEquals(int a, int b) {}} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:repeated-test-shape" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:repeated-test-shape] reason="..."tx0 explain tx0/java:repeated-test-shape shows the same in the terminal. Found a false positive? Report it.