org.sonar.l10n.java.rules.squid.S2924.html Maven / Gradle / Ivy
While some TestRule
classes have the desired effect without ever being directly referenced by a test,
several others do no, and there's no reason to leave them cluttering up the file if they're not in use.
This rule raises an issue when Test
class fields of the following types aren't used by any
of the test methods: TemporaryFolder
, and TestName
.
Noncompliant Code Example
public class ProjectDefinitionTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder(); // Noncompliant
@Test
public void shouldSetKey() {
ProjectDefinition def = ProjectDefinition.create();
def.setKey("mykey");
assertThat(def.getKey(), is("mykey"));
}
}
Compliant Solution
public class ProjectDefinitionTest {
@Test
public void shouldSetKey() {
ProjectDefinition def = ProjectDefinition.create();
def.setKey("mykey");
assertThat(def.getKey(), is("mykey"));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy