org.sonar.l10n.java.rules.squid.S2699.html Maven / Gradle / Ivy
A test case without assertions ensures only that no exceptions are thrown. Beyond basic runnability, it ensures nothing about the behavior of the code under test.
This rule raises an exception when no assertions are found in a JUnit test.
Noncompliant Code Example
@Test
public void testDoSomething() { // Noncompliant
MyClass myClass = new MyClass();
myClass.doSomething();
assertThat(myClass.doSomething()); // Fest assertion stub with no checks
}
Compliant Solution
@Test
public void testDoSomething() {
MyClass myClass = new MyClass();
assertNull(myClass.doSomething()); // JUnit assertion
assertThat(myClass.doSomething()).isNull(); // Fest assertion
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy