nutmix
(john little)
March 25, 2025, 7:37pm
1
Sonar is reporting hundreds of “blocker” issues with the title:
"Add at least one assertion to this test case"
the test methods in question have more than 20 assertions. What is happening?
import org.junit.Test;
import org.springframework.util.Assert;
public class PlayerTest {
@SuppressWarnings("deprecation")
@Test
public void testSplitPlayer() {
// code....
Assert.isTrue(response.getOutcomes().size() == playersMap.size());
Assert.notNull(response);
}
}
Why would it report that it needs at least one Assertion there are clearly already Assertions?
Can you share which version of spring you are using? I cannot see those assertion methods signatures in spring-core 6.2.
nutmix
(john little)
March 27, 2025, 9:35am
5
Its spring boot 2.7
Basically all our projects show zero percent test coverage, but we have significantly more than that.
How does sonar calculate the coverage? Does it do it by looking at the source, or by running the actual tests?
Here are some relevant parts of the pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven-jar-plugin.version>3.1.0</maven-jar-plugin.version>
<skipIntegrationTests>true</skipIntegrationTests>
</properties>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
nutmix
(john little)
March 31, 2025, 8:13am
6
We haven’t had any luck solving this issue unfortunately. It throws up all tests as not having assertions for no obvious reason.
I managed to reproduce the issue, indeed the analyzer is currently not aware of that Spring class for assertions.
I created this ticket which I am currently working on.
Thanks for the report!
The ticket was completed and it should be already released in SonarQube Cloud!