Skip to main content
.NETStandard2.0

Sonarqube test logger for vstest platform

Published
Dec 3, 2024
1y ago
Total Downloads
789
789

Install

dotnet add package Maurosoft.SonarqubeTestLogger --version 1.0.3
ProductVersions
.NET Standard
netstandard2.0

README

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

Changes from Previous Version

No structural changes between v1.0.1 and v1.0.3.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.