0

When I scan a multi-modular project for Sonar with the same projectBaseDir the unit test count is wrong. My groovy app has 80 unit tests, my java 0 and my javascript 0. Every time I scan my project, the unit test count ends up 240. If I take the java or the js modules out, it goes down to 160 and down to 80 if I remove the other two modules entirely. How can I have a modular project that shares the same root and won't double/triple count the unit tests? I shouldn't have to have a separate Sonar project or complete module sub-directory for each language I scan in the project.

Sonar 3.7.4, framework 1.4, Sonar-Runner 2.3, sonar-groovy-plugin-1.0-spantree-SNAPSHOT.jar

sonar.projectKey=com.me:myapp
sonar.projectName=MyApp
sonar.projectVersion=1.0
sonar.projectDescription=

sonar.modules=module-java, module-js,module-grvy

module-grvy.sonar.projectName=MyApp - Grails
module-grvy.sonar.language=grvy
module-grvy.sonar.sources=src/groovy
module-grvy.sonar.tests=test/unit
module-grvy.sonar.projectBaseDir=.

module-java.sonar.projectName=MyApp - Java
module-java.sonar.language=java
module-java.sonar.sources=src/java
module-java.sonar.tests=
module-java.sonar.projectBaseDir=.

module-js.sonar.projectName=MyApp - JavaScript
module-js.sonar.language=js
module-js.sonar.sources=web-app
module-js.sonar.tests=
module-js.sonar.exclusions=**/built/*.js
module-js.sonar.projectBaseDir=.

sonar.sourceEncoding=UTF-8
sonar.dynamicAnalysis=reuseReports
sonar.surefire.reportsPath=target/test-reports
sonar.core.codeCoveragePlugin=cobertura
sonar.cobertura.reportPath=target/test-reports/cobertura/coverage.xml
Dave Brunkow
  • 352
  • 6
  • 20
  • So the following might work for now, using the web-app directory as a module but it makes me want to go take a scalding shower to get clean afterwards. `module-js.sonar.projectName=MyApp - JavaScript module-js.sonar.language=js module-js.sonar.sources= module-js.sonar.tests= module-js.sonar.exclusions=**/built/*.js module-js.sonar.projectBaseDir=web-app` – Dave Brunkow Feb 13 '14 at 20:27
  • To be clear, using the web-app dir as my javascript module directory. Seems wrong. – Dave Brunkow Feb 13 '14 at 20:34
  • Have you tried defining the tests dir for the scr folders with no tests? – jeremyjjbrown Feb 20 '14 at 21:06

1 Answers1

0

You need to use modules for reporting unit test results to sonar if you need to see the unit test count appropriate to a module.

For explaining this, I will take a .NET example and you can relate it to any language for achieving similar working results.

Solution: Lets say I have three modules(dlls) as below.

  • MVP.Unit.Test.1.dll - 5 tests
  • MVP.Unit.Test.2.dll - 8 tests
  • MVP.Unit.Test.3.dll - 2 tests

I need to run the unit tests in these dlls separately so that separate unit test reports are generated for these test dlls. And the unit test reports are as follows.

  • MVP.Unit.Test.1.trx (.trx is the extension of unit test report in .NET world)
  • MVP.Unit.Test.2.trx
  • MVP.Unit.Test.3.trx

Now that I have separate unit test reports for different modules, we need to report this to sonar using properties file as following.

MVP.Unit.Test.1.sonar.cs.vstest.reportPaths=C:/Test/MVP.Unit.Test.1.trx MVP.Unit.Test.2.sonar.cs.vstest.reportPaths=C:/Test/MVP.Unit.Test.2.trx MVP.Unit.Test.3.sonar.cs.vstest.reportPaths=C:/Test/MVP.Unit.Test.3.trx

What the above configuration will do is, it will tell Sonar to properly map the unit test results with correct modules so that we get nice segmentation of unit tests according to their modules.

There you go. Now you'll be able to see the unit test count in Sonar as per the modules.

Raju Mandapati
  • 691
  • 6
  • 22