4

I have a project built with maven and I recently integrated Sonar... It is really easy to configure Sonar to analyze you're project but I couldn't configure it to run my project unit test also. I tried something with Jacoco but I get some Seam error and all the other tests are skipped. By the way I'm using TestNG to run tests manually.

Cœur
  • 37,241
  • 25
  • 195
  • 267
spauny
  • 4,976
  • 9
  • 44
  • 61

2 Answers2

4

You can use the relevant Analysis Parameters of sonar to reuse the test reports from your earlier run. You would set sonar.dynamicAnalysis property to reuseReports and specify the location of the reports in sonar.jacoco.reportPath or sonar.surefire.reportPath based on how you run the tests.

By the way, mvn sonar:sonar invokes maven's test goal, which runs unit tests as part of the analysis. So ideally if your maven can run unit tests, sonar should be able to run them.

Raghuram
  • 51,854
  • 11
  • 110
  • 122
2

Sonar cannot run tests, it can only analyze testing reports.

You can run yourself JUnit ( using Maven or Ant for exemple ) and push reports to Sonar (try Sonar's Maven plugin for that)

or you can give yourself a build factory (try hudson for exemple) and plug it to sonar.

Giovanni P.
  • 1,017
  • 15
  • 23
mabroukb
  • 691
  • 4
  • 11
  • Well then I want to reuse TestNG results. Isn't a way to show sonar the path to these results (xml file)? – spauny Aug 10 '12 at 13:30
  • This is not true, Sonar can run tests. If you look at the documentation http://docs.codehaus.org/display/SONAR/Analyzing+with+Maven you will see they recommend turning off tests in the Maven build to avoid them being run twice, once when you build, once when you use Sonar. – Mark Butler Aug 18 '13 at 12:59
  • both analyses you're talking about are run with maven : first one during maven install goal, second one during maven sonar goal – mabroukb Aug 25 '13 at 09:00
  • 1
    @MarkButler your link is dead. Also, according to this https://www.sonarsource.com/blog/unit-test-execution-in-sonarqube/ sonar dropped the unit test execution. – JRichardsz Apr 13 '23 at 14:54