New Java unit test causes quality gate to fail because it has no unit tests

  • SonarQube version 8.9.6 (build 50800)
  • Add a new Java unit test to my project

We’ve run into another problem with the SonarQube new/updated code detection on branches.

This time, a new Java junit test was added to the project. SonarQube detected it as new/updated code, however, it is failing the quality gate saying that the unit test does 0% unit test coverage! This is a Maven project and the unit test is in src/test/java. The class file is named appropriately as *Test.java. And the unit test has junit annotations for executing the tests. The project also has a number of other junit tests exactly like this and SonarQube is not looking for unit test coverage on them.

So, any thoughts as to why SonarQube is looking for unit test coverage on a unit test?

Thanks!

Hi,

It sounds like this is a problem not of new/overall code but of sources versus tests. Because if it’s truly being analyzed as a test, then you wouldn’t be being dinged for lack of coverage.

To test my initial hypothesis, could you provide a screenshot of the file in question in the Code tab? In particular, I’m interested to see what icon is shown to the left. E.G.
Selection_381
Selection_380

 
Ann

Screenshot 2022-08-16 145755

Hi,

That icon indicates your file is being treated as source code.

So you need to sort out your sonar.sources value versus your sonar.tests. Care to share the values?

 
Ann

Ok so these were not set by the application but looking at the logs they are both set to the “src” directory. Which would explain Sonar’s behavior. so I thanks for the help, I think I got this answered.

1 Like

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