2

I'm using SonarQube and Jenkins. In Jenkins, I check the unit tests with nUnit and the coverage with opencover. The opencover's report is displayed in Sonar but the nunit's report is not. The Unit Tests count is not even displayed in the home page of the project.

Here is what I do :

  1. Build my VisualStudio project with MSBuild
  2. Run nunit and opencover with a batch command line
  3. Run SonarQube scanner's analysis
  4. Package the project

The Step 2's command line :

MKDIR "%WORKSPACE%\reports"
MKDIR "%WORKSPACE%\reports-history"

SET COV_PTH="D:\Programmes\opencover.4.5.3522"
SET TOOL_PATH="D:\Programmes\NUnit-2.6.4"
SET RPT_PATH="D:\Programmes\ReportGenerator"

copy src\Foo.Bar.Tests\app.config build\Foo.Bar.Tests.dll.config

%COV_PTH%\OpenCover.Console.exe "-filter:+[Foo.Bar*]* -[Foo.Bar.Tests]* -[Foo.Bar.Service]* -[Foo.Bar.Domain]* -[Foo.Bar.Dal]Foo.Bar.Dal.Dao.* -[Foo.Bar.Controller]Foo.Bar.Controller.*Comparer -[Foo.Bar.Controller]Foo.Bar.Controller.External.*" -register "-target:%TOOL_PATH%\bin\nunit-console.exe" -targetargs:"build\Foo.Bar.Tests.dll /noshadow /result=reports\TestResult.xml" -output:reports\opencovertests.xml

%RPT_PATH%\ReportGenerator.exe "-reports:reports\opencovertests.xml" "-targetdir:reports-ReportGenerator" "-historydir:reports-history"

The Step 3's parameters :

sonar.projectKey=FooBar
sonar.projectName=FooBar
sonar.projectVersion=%SVN_REVISION%
sonar.sources=src/Foo.Bar.Controller, src/Foo.Bar.Dal, src/Foo.Bar.Domain, src/Foo.Bar.Fichier, src/Foo.Bar.Generation, src/Foo.Bar.Reporting, src/Foo.Bar.Service, src/Foo.Bar.Web
sonar.binaries=Build/Foo.Bar.Controller.dll, Build/Foo.Bar.Dal.dll, Build/Foo.Bar.Domain.dll, Build/Foo.Bar.Service.dll, Build/Foo.Bar.Fichier.exe, Build/Foo.Bar.Generation.exe, Build/Foo.Bar.Reporting.exe
sonar.tests=src/Foo.Bar.Tests
sonar.cs.opencover.reportsPaths=reports/opencovertests.xml
sonar.cs.nunit.reportsPaths=reports/TestResult.xml

EDIT

I also tried the following process (same results) :

  1. Prepare SonarQube scanner's analysis
  2. Build my VisualStudio project with MSBuild
  3. Run nunit and opencover with a batch command line
  4. End SonarQube scanner's analysis
  5. Package the project

END EDIT

The nUnit's report is well generated in workspace/reports/TestResult.xml.

I tested the analysis generation by command line and via the sonarqube plugin for jenkins. I got the same results.

Can you see anything wrong?

Is there any SonarQube's logs that I could checked ?

I am using Jenkins 2.10, MSBuild 12, SonarQube 5.6, SonarQube scanner for Jenkins plugin 2.4.3, opencover 4.5 and nunit 2.6.4

EDIT

I updated my config : Jenkins 2.18, MSBuild 14, SonarQube scanner for Jenkins plugin 2.4.4. Same results.

END EDIT

jBravo
  • 873
  • 1
  • 9
  • 28
  • Found logs in /data/ce/ but there is nothing interesting here (no error, no warn, only info). – jBravo Jul 25 '16 at 12:30
  • I am still stuck. Tell me if you need more details. – jBravo Jul 29 '16 at 08:24
  • Did you find any solution? I'm running in exactly the same behavior, no unit tests results at all in sonarqube(and no code coverage). I've the static code analysis. – J4N Feb 08 '17 at 09:09

1 Answers1

2

Take a look at: SonarQube documentation: Unit Test Execution Results Import (C#, VB.NET)

It says:

Drilldown on Test Execution Results is not supported

My understanding is that you can only see the results (number of Tests passing, errors, etc) but not detail from the tests.

You also ask about Logs. You have:

JosephS
  • 744
  • 5
  • 22
  • In my case, tests execution results are not even displayed. But thanks for the clue, I will follow the SONARNTEST-22 feature. – jBravo Aug 10 '16 at 07:04
  • Have you looked into the Project Dashboard in Sonar? There I can see the totals....but, if I go where it is supposed to "list" the tests it says something down the line of "No tests" or "No Results" – JosephS Aug 10 '16 at 13:18
  • Another suggestion, I call nUnit indicating the path to the result XML by passing the argument "xml" instead of the one you use: "result". – JosephS Aug 10 '16 at 13:27
  • The Project Dashboard displays the test's coverage but not the results of the tests. I already tryed the xml argument but in vain. – jBravo Aug 10 '16 at 13:46
  • How about using absolute paths to the result file? – JosephS Aug 10 '16 at 14:04
  • I just tryed but unfortunately it did not change anything. Note that the coverage report - which is in the same directory that the nUnit report - is also passed in relative and correctly displayed. Thanks for your suggestions. – jBravo Aug 10 '16 at 14:31
  • No, I did not find any useful information in the logs. – jBravo Aug 12 '16 at 07:44
  • Looking at your steps, thats not how I'm running mine. – JosephS Aug 12 '16 at 14:06
  • Ok, so what did i miss? – jBravo Aug 12 '16 at 14:10
  • Looking at your steps, that's not how I'm running mine. In Jenkins 1) first I add a _SonarQube Scanner for MSBuild - Begin Analysis_ command, there I add the two additonal arguments _sonar.cs.opencover.reportsPaths_ and _sonar.cs.nunit.reportsPaths_ for Sonar to process the reports, 2) then a _Windows batch command_ to rebuild the solution, 3) then another _Windows batch command_ to trigger OpenCover (which triggers nUnit) and 4) Lastly a _SonarQube Scanner for MSBuild - End Analysis_ command – JosephS Aug 12 '16 at 14:13
  • I see you call report generator, Sonar doesn't need it, Sonar consumes the XML output from OpenCover as well as the XML resul from nUnit – JosephS Aug 12 '16 at 14:32
  • Take a look at their documentation, there they do it by windows command line: [Code Coverage Results Import (C#, VB.NET)](http://docs.sonarqube.org/pages/viewpage.action?pageId=6389770) – JosephS Aug 12 '16 at 14:34
  • Just double checking my initial answer suggestion: go to _SonarQube_, click on your project, this will take your to _Home_ page of the project, you will see the _Coverage %_ and the _Unit Tests count_. Is the count of the Unit Tests equal to zero (0)? Mine says the correct count of Unit Tests. If then click on the count it will take you to another screen, that screen is useless, it lists no Tests, just the count again. **that is OK**. Then, If you click on Dashboard->Custom there you will see the totals of the Tests (failures, errors, skipped, time) that's all you get. – JosephS Aug 12 '16 at 14:46
  • I changed my build process for yours but still have no tests results nor unit tests count in the home page of the project. Thanks for your suggestions. – jBravo Aug 12 '16 at 15:10
  • You mention in your question that are using MSBuild 12, check out [Analyzing with SonarQube Scanner for MSBuild](http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild) they mention **MSBuild 14**. I recently had an issue with my coverage not getting imported and they only way It got _"fixed"_ was after an update of VS 2015 to latest (Update 3) – JosephS Aug 12 '16 at 18:36
  • I did another test with MSBuild 14 but the behaviour remains the same. – jBravo Aug 16 '16 at 07:51