0

I am new to sonar and trying to use Sonar for code analysis including code coverage, unit test report etc. I am able to generate a report using OpenCover, i am using C#. My project is part of a jenkins job which build the soluton, run script for Opencover and then connect to sonar using 'Execute sonarQube scanner'. I am able to view result as line of code smell, issues in sonar. But unit test section is showing 0 in all parts (Failures, errors, tests). Below are my sonar setting in sonar-project.properties.

sonar.projectKey=TestCI
sonar.projectVersion=1.0
sonar.projectName=TestCI
sonar.sources=.
sonar.language=cs
sonar.cs.vstest.reportsPaths="%WORKSPACE%\AutoBuildTest\Results.trx"
sonar.dotnet.visualstudio.solution.file="%Workspace%\TestCI.sln"
sonar.cs.msbuild.testProjectPattern=*Tests;*UnitTests
sonar.cs.opencover.reportPaths="%WORKSPACE%\GeneratedReports\TestCI.xml"
sonar.cs.vscoveragexml.reportsPaths="%WORKSPACE%\GeneratedReports\TestCI.xml"

Please help.

Jens
  • 67,715
  • 15
  • 98
  • 113
Monica
  • 93
  • 1
  • 12
  • do you have content in the testci.xml file? – Shaun Wilde Jul 07 '16 at 21:47
  • Yes i do but i found sonar tries to read data directly under workspace and my xml is under a directory in workspace, so i am trying to bring it at workspace level and see if sonar can read it after changes. – Monica Jul 08 '16 at 04:29
  • sonar can read xml file now but still execution is failure with message --expected "unitTest" but got "CoverageSession" – Monica Jul 08 '16 at 05:04
  • I suspect you are supplying the wrong file for one of the reports - I doubt that `TestCI.xml` is both from opencover and vscoveragexml – Shaun Wilde Jul 09 '16 at 02:21
  • I was using open cover, turned out sonar source has stopped supporting it – Monica Jul 11 '16 at 09:52
  • really - I use it on nemo.sonarsource.org - appears to still work – Shaun Wilde Jul 12 '16 at 02:24
  • I have configured sonarQube on my machine and trying to integrate with jenkins. I am following localhost:9000 url to access sonar. On sonarSource.org, i can see almost everything that i can see on my local sonar server except unit test coverage and line coverage. How do i achieve that since sonar says they are no longer supporting gallio/open cover – Monica Jul 12 '16 at 04:04
  • Thanks Shaun for your help, i figured it out :) Thanks again!! – Monica Jul 14 '16 at 03:59
  • awesome don't forget you can answer your own post to help others who may have the same issue in the future. – Shaun Wilde Jul 14 '16 at 07:09

1 Answers1

1

So i was trying to get my head around this, googling around and not finding concrete solution.

I am new to CI, so i do not know many things. I wanted to perform code coverage for my .net application which is running as a jenkins job (build and test steps already configured). I was able to integrate sonarqube as well.

Next step was to cover the code and show output in sonar (all as part of jenkins job). I tried opencover and could see the html output but could not integrate it in sonar. Tried dotCover also but not much use. I was not aware about Galileo so tried that also and it did not work. Then i started coming across post that says Galileo is no longer supported by sonar (version higher than 4.3 and mine was 5.3).

SO i had to start from ground zero again, leaving opencover and dotcover behind. I started looking into visual studio's code coverage tool which was apparently not supported on my version (VS 2015 professional). So i changed it to VS 2015 Enterprise. Now i could access code coverage tool under "%VS_INSTALL_DIR%\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools". Next step was to integrate all this in jenkins. I had to use "collect" with code coverage tool (giving my tests project dll as input) and then run "analyze" on code coverage tool (which basically converts binary file generated in "collect" to xml file).

Now when i ran this from my machine, from my development project's dll, it all worked fine and i could run sonar-runner (in command line after changing to path of my project) i could see the magical output in sonarqube server (the one that runs on localhost:9000). But when i repeated same in jenkins (using batch command) nothing happened. What went wrong

  1. Make sure sonar-project.properties file is correct.
  2. When i could not find anything in sonar i checked the xml file getting generated by code coverage tool (using analyze step). There reference for dll was from my local project and not the one i am building in jenkins. I opened project downloaded by jenkins from github (as part of build step). The reference was all fine. Test project was pointing to project downloaded from github. SO where was the error?

I forgot to rebuild the solution so that it will clear the old reference and build new one with new location.

It looks long answer but it took me longer to figure out (although i read it during my R&D but could not understand why would i need it)

Thanks Shaun for suggestions. I still could not figure out how opencover is running on nemo.sonarsource.org (version is 5.6) but i will save that for some other day.

Monica
  • 93
  • 1
  • 12