All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S2699.html Maven / Gradle / Ivy

There is a newer version: 8.9.0.37768
Show newest version

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