Skip to content

maurosoft1973/SonarqubeTestLogger

Repository files navigation

Sonarqube Test Logger

Sonarqube xml report extension for Visual Studio Test Platform.

NuGet Downloads

Packages

Logger Stable Package
Sonarqube NuGet Version

Usage

The Sonarqube Test Logger generates xml reports in the Generic test execution report format.

To use the logger, follow these steps:

  1. Add a reference to the Sonarqube Test Logger nuget package in test project

    dotnet add package Maurosoft.SonarqubeTestLogger
    
  2. Use the following command line in tests

    dotnet test --logger:sonarqube
    
  3. Test results are generated in the TestResults directory relative to the test.csproj. The default report name is SonarqubeReportTest.xml

A path for the report file can be specified as follows:

dotnet test --logger:"sonarqube;LogFilePath=test-result.xml"

test-result.xml will be generated in the same directory as test.csproj.

Note: the arguments to --logger should be in quotes since ; is treated as a command delimiter in shell.

Logger Configuration

  • LogFileName: Use LogFileName to specify the name of the output log file. The file will be created in the default results directory (TestResults) relative to test project.

    # Assume we have this directory structure of tests
    > tree
    .
    │ TestProject1.sln
    ├── TestProject1
    │   ├── UnitTest1.cs
    │   └── TestProject1.csproj
    
    > dotnet test --logger:"sonarqube;LogFileName=mytestfile.xml"
    
    # Note the output file
    > tree
    .
    │ TestProject1.sln
    ├── TestProject1
    │   ├── TestResults
    │   │   ├── mytestfile.xml    # test result file
    │   ├── UnitTest1.cs
    │   └── TestProject1.csproj
    
  • LogFilePath: Use this option to provide an absolute path for the result file. The parent directory will be created if it doesn't exist.

    # Assume we have this directory structure of tests
    > tree
    .
    │ TestProject1.sln
    ├── TestProject1
    │   ├── UnitTest1.cs
    │   └── TestProject1.csproj
    
    > dotnet test --logger:"sonarqube;LogFilePath=mytestfile.xml"
    
    # Note the output file
    > tree
    .
    │ TestProject1.sln
    ├── TestProject1
    │   ├── mytestfile.xml    # test result file
    │   ├── UnitTest1.cs
    │   └── TestProject1.csproj
    
  • Verbose: If true, log message to console

    # Assume we have this directory structure of tests
    > tree
    .
    │ TestProject1.sln
    ├── TestProject1
    │   ├── UnitTest1.cs
    │   └── TestProject1.csproj
    
    > dotnet test --logger:"sonarqube;Verbose=true"
    
    The output on console:
    
    sonarqube - Start
    sonarqube - LogFileName      ->
    sonarqube - LogFilePath      -> mytestfile.xml
    sonarqube - TestRunDirectory -> C:\Users\Test\source\repos\TestProject1\TestProject1\TestResults
    sonarqube - PathSourcesTest: -> C:\Users\Test\source\repos\TestProject1\TestProject1
    sonarqube - Found Test with Namespace -> TestProject1, ClassName -> Class1, MethodName -> TestMethod1 from TestResults
    sonarqube - Found Test with Namespace -> TestProject1, ClassName -> Class1, MethodName -> TestMethod2 from TestResults
    sonarqube - Search test with namespace:TestProject1, classname:Class1, methodname: Test1 from source file -> C:\Users\Test\source\repos\TestProject1\TestProject1\Class1.cs
    sonarqube - Found Namespace TestProject1 into file C:\Users\Test\source\repos\TestProject1\TestProject1\Class1.cs at line 7
    sonarqube - Found Class Class1 into file C:\Users\Test\source\repos\TestProject1\TestProject1\Class1.cs at line 10
    sonarqube - Found Method TestMethod1 into file C:\Users\Test\source\repos\TestProject1\TestProject2\Class1.cs at line 13
    ...
    ...
    sonarqube - End
    
    # Note the output file
    > tree
    .
    │ TestProject1.sln
    ├── TestProject1
    │   ├── TestResults
    │   │   ├── mytestfile.xml    # test result file
    │   ├── UnitTest1.cs
    │   └── TestProject1.csproj
    

License

MIT

About

Sonarqube test logger for vstest platform

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages