Tests should include assertions (java:S2699) : rest assured not dectected

Hello,

sonar lint 5.0 says Tests should include assertions (java:S2699) but my code with rest assured do testing.

  @Test
  public void testCreateUser() {
    String username = "testCreateUser";
    String user = buildJsonApiUser(username, "test");

    // @formatter:off
        given().
            accept(JsonApiHttpMessageConverter.APPLICATION_JSON_API_VALUE).
            contentType(JsonApiHttpMessageConverter.APPLICATION_JSON_API_VALUE).
            body(user).

        when().
            post(UserController.RESOURCE).

        then().
            statusCode(201).
            body("data.id", notNullValue()).
            body("data.attributes.username", is(username)).
            body("data.attributes.password", is(emptyOrNullString()));
        // @formatter:on
  }

Example of test which fails

Hi Olivier,

The rule java:S2699 is supposed to support REST-assured. It has been implemented to detect the presence of a list of methods like statusCode or body of the io.restassured.response.ValidatableResponseOptions interface. The rule initially supports REST-assured 3.0.2 and should also work for the latest version 4.2.0 because it’s the same method names.
But I notice that the rule java:S2699 is not able to find methods like statusCode and body when the bytecode of the class io.restassured.response.ValidatableResponseOptions is not available to SonarJava, method symbols are resolved as unknown and this raises false-positives.
It could be caused by SonarLint that does not resolve properly the test classpath. To validate this hypothesis, could you confirm that in SonarQube (or SonarCloud) you have no false-positive and only true positive about this rule?

2 Likes