This page documents versions 2.1 and below of the C# plugin. For newer versions, consult this page.
If you reached this page from a link, please send a note to email@example.com (you'll have to join first.)
If you reached this page from a bookmark, please update it.
There are two different ways to feed the SonarQube platform with information on unit tests test execution and code coverage:
- Let the SonarQube platform drive the execution of the unit tests and the code coverage tool
- Reuse reports that have been generated by external tools prior to the SonarQube analysis
These two Both ways use are handled by Gallio. So , so you first have to install Gallio on the machine(s) running the SonarQube analysis. You also have to install the code coverage tool of your choice that will be driven by Gallio. Supported tools are dotCover, NCover, OpenCover and PartCover.
- Set the path to the Gallio installation directory through the
- Define which tool to use to compute the code coverage through the
sonar.gallio.coverage.toolproperty. Then , set the installation directory of this code coverage tool through the
sonar.partcover.installDirectoryproperty. Note that there is not such a property for NCover as because the installation path location of NCover is automatically discovered by Gallio.
This is the default mode.
The first and unique step is to tell SonarQube which projects are unit test projects. To do so, set the
# Semicolon-separated list of patterns to identify unit test projects # Default value is *.Tests sonar.donetdotnet.visualstudio.testProjectPattern=*.Tests;*.UnitTests
Then, you just have to run a SonarQube analysis and you'll get data on unit tests and code coverage. Indeed, the The paths to the unit test assemblies are automatically retrieved from the Visual Studio ".csproj" files. And , and the execution of unit tests and the driving of the coverage tool is automatically performed by Gallio.
Then , you just need to provide SonarQube with the following reports: unit tests configure the paths to the unit test execution and code coverage reports.
# Paths are relative to the Solution base directory # Path to the unit tests execution report sonar.gallio.reports.path=reports/gallio-report.xml # Path to the code coverage report sonar.gallio.coverage.reports.path=reports/coverage-report.xml
The following command lines are launched while letting the SonarQube platform drive reuseReport mode has been tested with the output of the following commands, which are the ones used when the SonarQube platform drives the execution of the unit tests and the code coverage tool. The reuseReport mode has been tested with those command lines. That's why it It is highly recommend to that you generate your reports using similar command lines:
The first and unique step is to tell SonarQube which projects are integration test projects. To do so, set the
# Semicolon-separated list of patterns to identify integration test projects sonar.donetdotnet.visualstudio.itProjectPattern=*.Integration.Tests;*.IntegrationTests
Then , you you just have to run a SonarQube analysis and you'll get data on integration tests and code coverage. Indeed, the The paths to the integration test assemblies are automatically retrieved from the Visual Studio ".csproj" files. And , and the execution of integration tests and the driving of the coverage tool is automatically performed by Gallio.
Then , you just need to provide SonarQube with the following reports: configure the paths to the integration tests execution report and the code coverage report.
# Paths are relative to the Solution base directory # Path to the integration tests execution report sonar.gallio.it.reports.path=reports/it-gallio-report.xml # Path to the code coverage report sonar.gallio.it.coverage.reports.path=reports/it-coverage-report.xml
This might happen if you have generated the reports then moved the files of your solution. Indeed, in 's files. In the XML coverage files, the paths to the C# source files must be the same as the paths specified in the ".csproj" files, otherwise the coverage data are simply not taken into account.
This error happens when one of the dotnet config files (app.config, web.config, ...) of in your Visual Studio solution specifies a runtime version not supported by the instance of Gallio. This is often the case when the following XML fragment appears in an app.config file:
The "sku" attribute is not something understandable by Gallio understands. If you replace the above XML fragment with the one below, the issue is solved:
If in the logs you get something such aslike:
[INFO] [23:30:05.643] A fatal exception occurred while running tests. Possible causes include invalid test runner parameters and stack overflows. [INFO] [23:30:05.727] Gallio.Model.ModelException: An exception occurred while invoking a test driver. ---> Gallio.Model.ModelException: Gallio.Model.ModelException: Could not load test assembly from 'C:\whatever\MyTestAssembly.Test.dll'. ---> System.BadImageFormatException: Could not load file...
it might be because some of your assemblies have been compiled with a x86 profile (32 bits-bit) while Gallio is configured to run in an "Any CPU" mode, hence 64bits 64-bit on your system.
This problem might be solved using corflags tool to force Gallio to run in a 32 bits -bit mode as shown below:
corFlags.exe Gallio.Echo.exe /32BIT+ /Force