简体   繁体   中英

Sonarqube squid:S2699 if jsonPath validation

I have implemented controller test (using spring web testing framework).

mvc.perform(MockMvcRequestBuilders.post("/calendar").contentType(V1_0)
            .content(toJSON(createCalendarDto(expectedCalendar))))
            .andExpect(status().isOk())
            .andExpect(content().contentTypeCompatibleWith(V1_0))
            .andExpect(jsonPath("$.id", is(notNullValue())))
            //...
            .andExpect(jsonPath("$.email", is(expectedCalendar.getEmail())));

this test covers some important cases, checking json structure and field values.

Test works correctly, sonar prints a message:

Tests should include assertions. Code smell Critical squid:S2699

I could use workaround like @SuppressWarnings("squid:S2699") but I hope it can be managed in better way.


java 1.8 Sonarcube Version 6.3.1 Spring-boot 1.4.3

You've found a false positive in a rule. Specifically, your test framework is not taken into account by the rule.

The best course for rule false positives in general is to open a thread on the SonarQube Google Group saying, essentially, "For language L, could you add case X to rule Y, please?". Don't forget to include a minimum code sample to reproduce the false positive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM