Skip to content

sonar.cxx.nunit.reportPaths

guwirth edited this page Mar 10, 2021 · 5 revisions

Overview

Sensor to read reports from the NUnit testing framework . NUnit is a unit-testing framework for all .Net languages, initially ported from JUnit.

Many C++ developers use NUnit to develop component tests, especially in the context of the Component Object Model (COM) developed by Microsoft.

Meanwhile, NUnit support is part of SonarQube. If possible sonar.cs.nunit.reportsPaths should be used.

Note: The cxx plugin itself does not run any tools, you have to do that yourself beforehand. The sensor only reads the report generated by a tool!

Supported versions

Create report

In order to generate a fitting report, make sure:

  • that the paths in the report matches the sonar.sources and sonar.tests lists in sonar-project.properties
  • the path can be absolute or relative to the project base directory

NUnit provides three different runners, which may be used to load and run your tests. The Console Runner, nunit-console.exe, is used for batch execution.

Sample command lines:

nunit3-console.exe MyTests.dll --result="report.xml;format=nunit2" --labels=ALL ...

Example of a report file

If the tool was executed successfully, a report like the example below should be generated:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--This file represents the results of running a test suite-->
<test-results name="c:\git\sonar-nunit\Sonar.NUnit\bin\Debug\Sonar.NUnit.dll" total="200" errors="30" failures="20" not-run="5" inconclusive="4" ignored="3" skipped="2" invalid="1" date="2014-08-15" time="09:02:13">
  <environment nunit-version="2.6.0.12051" clr-version="2.0.50727.5483" os-version="Microsoft Windows NT 6.1.7601 Service Pack 1" platform="Win32NT" cwd="c:\git\sonar-nunit" machine-name="machine" user="user" user-domain="domain" />
  <culture-info current-culture="en-GB" current-uiculture="en-US" />
  <test-suite type="Assembly" name="C:\sonar-examples\projects\languages\csharp\NUnitTestProject1\bin\Debug\NUnitTestProject1.dll" executed="True" result="Success" success="True" time="0.051" asserts="0">
    <results>
      <test-suite type="Namespace" name="NUnitTestProject1" executed="True" result="Success" success="True" time="0.046" asserts="0">
        <results>
          <test-suite type="TestFixture" name="NUnitTest1" executed="True" result="Success" success="True" time="0.045" asserts="0">
            <results>
              <test-case name="NUnitTestProject1.NUnitTest1.NUnitTestMethod1" executed="True" result="Success" success="True" time="0.041" asserts="2" />
            </results>
          </test-suite>
        </results>
      </test-suite>
    </results>
  </test-suite>
</test-results>

Configure cxx plugin

  1. First check if the file extensions read in by the cxx plugin are set (sonar.cxx.file.suffixes).
  2. That the paths in the report matches the sonar.sources and sonar.tests lists in sonar-project.properties.
  3. Set the analysis parameter sonar.cxx.nunit.reportPaths in the configuration file sonar-project.properties of your project. The Report Paths link describes the configuration options.
  4. Execute the SonarScanner to transfer the project with the report to the SonarQube Server.

Sample for sonar-project.properties:

sonar.cxx.nunit.reportPaths=report.xml

Troubleshooting

Clone this wiki locally