S2699 Tests should include assertions false positive for andExpect

Hi Sonar Team!

I’m experiencing a false positive with rule S2699. The rule description explicitly mentions support for Spring’s org.springframework.test.web.servlet.ResultActions.andExpect(), so I expect the following test to be compliant.
However this is not the case, I do get an error for this test.

SonarQube 7.6
SonarJava 5.11

Example test:

// springframework MockMvc used
void myTest() throws Exception {

I think this is a false-positive.

Cheers and thanks for the help,



I’m having the same issue.
Does someone have an idea to solve that ?

Now in our projects we have hundreds of those false positive that are making noise and hiding the other issues




I confirm andExpect is considered by S2699 as you can see in the code

I can’t reproduce your problem with this reproducer:

import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class AssertionsInTestsCheckTest {

  WebApplicationContext wac;

  private MockMvc mockMvc;

  public void setup() {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();

  public void testWithNoAssertion1() { // Noncompliant
  void myTest1() throws Exception { // Compliant

… using: org.springframework:spring-test:4.0.5.RELEASE

Which version of spring-test are you using?
Can you share a reproducer?


Hi @Maxime,

Any news on my questions?

Hi @Alexandre_Gigleux,
i have the same issue with
spring-test version 5.2.4.RELEASE.
SonarQube Version: Community Edition Version 7.9.2 (build 30863)
Java Code Quality and Security plugin 6.3 (build 21585) installed

Edit: updating SonarQube (or the java analyzer version), also solved this problem for some users.


Before starting, I just want to warn that my post targets recent versions of the plugin (>=6.0). It might or might not be related to the initial problem raised by this post.

Such unexpected behavior is typically due to missing bytecode of dependencies.
I discussed a similar issue in this post, it does not target the same rule nor the same method, but I believe the solutions proposed there could be relevant to you.

Feel free to get back to us if it does not.



We have the same issue in our projects, we sent you a screenshot.


Hello @Ernesto,

Did you have a look at the post that I linked in my previous message?
If yes, can you briefly describe what you tried? Do you see anything special in the logs of the analysis?

In addition, it would be helpful to know the version of the scanner, Sonarqube, and optionally the java analyzer version if you updated it at one point.


We solve that updating the java analyzer version.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.