Skip to end of metadata
Go to start of metadata

.NET Test Execution Results are imported into SonarQube in 4 steps:

  1. Run the SonarScanner.MSBuild.exe begin command, specifying the absolute path where the test execution report will be available using the /d:propertyKey="path" syntax ("propertyKey" depends on the test runner tool)
  2. Build your project using MSBuild
  3. Run your test runner tool, instructing it to produce a report at the same location specified earlier to the MSBuild SonarQube Runner
  4. Run the SonarScanner.MSBuild.exe end command

Importing multiple reports

You can import reports from different tools by passing several /d:propertyKey="path" arguments (with different property keys) to the SonarScanner.MSBuild.exe begin command.

Multiple reports from the tool are supported by:

  • Either separating paths with commas: /d:propertyKey="path1,path2,path3"
  • Or using wildcards (*, **, ?): /d:propertyKey="path/*.xml,/path/**/*.xml,/path/testreports/testreport?.xml"

Visual Basic .NET support

Examples on this page are for C#. VB.NET Plugin users should replace ".cs." by ".vbnet." in all property name. Example: "sonar.cs.vstest.reportsPaths" becomes "sonar.vbnet.vstest.reportsPaths".

Drilldown on Test Execution Results is not supported

Tests execution results will be displayed on project level dashboards. However, if it shows for example 2 test failures, clicking on it to drilldown will not show which 2 tests are failing.

Here are the exact steps to import Unit Test Execution Results for each of the supported tool, using the SonarQube Scanner for MSBuild from the command line:

VSTest

  1. Open a Developer Command Prompt for Visual Studio
  2. Put yourself in the root folder of the project you want to analyze
  3. Run the following commands:
Begin the SonarQube Analysis and provide all required properties, including "sonar.cs.vstest.reportsPaths"
SonarScanner.MSBuild.exe begin /k:"sonarqube_project_key" /n:"sonarqube_project_name" /v:"sonarqube_project_version" /d:sonar.cs.vstest.reportsPaths="%CD%\TestResults\*.trx"
Build the project, for example:
msbuild
Run Unit Tests and Save Results in the "TestResults" folder using a generated *.trx filename
"%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" /Logger:trx "UnitTestProject1\bin\Debug\UnitTestProject1.dll"
End the SonarQube Analysis and upload it to the SonarQube server
SonarScanner.MSBuild.exe end

NUnit

  1. Open a Developer Command Prompt for Visual Studio
  2. Change the current folder to the root folder of the project you want to analyze
  3. Run the following commands:
Begin the SonarQube Analysis and provide all required properties, including "sonar.cs.nunit.reportsPaths"
SonarScanner.MSBuild.exe begin /k:"sonarqube_project_key" /n:"sonarqube_project_name" /v:"sonarqube_project_version" /d:sonar.cs.nunit.reportsPaths="%CD%\NUnitResults.xml"
Build the project, for example:
msbuild
Run Unit Tests and Save Results in file "NUnitResults.xml"

packages\NUnit.ConsoleRunner.3.7.0\tools\nunit3-console.exe --result=NUnitResults.xml "NUnitTestProject1\bin\Debug\NUnitTestProject1.dll"

or, for older NUnit 2

"%ProgramFiles(x86)%\NUnit 2.6.4\bin\nunit-console.exe /result=NUnitResults.xml "NUnitTestProject1\bin\Debug\NUnitTestProject1.dll"

End the SonarQube Analysis and upload it to the SonarQube server
SonarScanner.MSBuild.exe end

MSTest

  1. Open a Developer Command Prompt for Visual Studio
  2. Put yourself in the root folder of the project you want to analyze
  3. Run the following commands:
Begin the SonarQube Analysis and provide all required properties, including "sonar.cs.vstest.reportsPaths"
SonarScanner.MSBuild.exe begin /k:"sonarqube_project_key" /n:"sonarqube_project_name" /v:"sonarqube_project_version" /d:sonar.cs.vstest.reportsPaths="%CD%\MSTestResults.trx"
Build the project, for example:
msbuild
Run Unit Tests and Save Results in file "MSTestResults.trx"
"%VSINSTALLDIR%\Common7\IDE\MSTest.exe" /testcontainer:"UnitTestProject1\bin\Debug\UnitTestProject1.dll" /resultsfile:MSTestResults.trx
End the SonarQube Analysis and upload it to the SonarQube server
SonarScanner.MSBuild.exe end

xUnit

SonarC# minimum requirement

SINCE C# 5.1

  1. Open a Developer Command Prompt for Visual Studio
  2. Put yourself in the root folder of the project you want to analyze
  3. Run the following commands:
Begin the SonarQube Analysis and provide all required properties, including "sonar.cs.xunit.reportsPaths"

Scanner.MSBuild.exe begin /k:"sonarqube_project_key" /n:"sonarqube_project_name" /v:"sonarqube_project_version" /d:sonar.cs.xunit.reportsPaths="%CD%\XUnitResults.xml"

Build the project, for example:
msbuild
Run Unit Tests and Save Results in file "XUnitResults.xml"

packages\xunit.runner.console.2.1.0\tools\xunit.console.exe XUnitProject1\bin\Debug\XUnitProject1.dll -xml XUnitResults.xml

End the SonarQube Analysis and upload it to the SonarQube server
SonarScanner.MSBuild.exe end
  • No labels