We are using SonarQube Server v2025.3.1 (109879) and is deployed with Docker.
We are running unit tests for our C# projects on a build agent and the tests are running fine and produce either a trx or a xunit log and an opencover file for the coverage. Commands we use are:
The information is however no longer correctly processed or uploaded to SonarQube and we have lost the information about the unit tests results and coverage.
The issue appeared with 2025.1 version upgrade where we cannot include any unit test result execution bellow is a sample with verbose = true
08:14:20.676 DEBUG: Pattern matcher extracted prefix/absolute path '/agent/_work/1/s/PROJECT/Sources/UnitTests/Email' from the given pattern '/agent/_work/1/s/PROJECT/Sources/UnitTests/Email/**/*TestResults.trx'. 08:14:20.677 DEBUG: Gathering files for wildcardPattern '**/*TestResults.trx'. 08:14:20.687 DEBUG: Pattern matcher returns '1' files. 08:14:20.688 INFO: Parsing the Visual Studio Test Results file '/agent/_work/1/s/PROJECT/Sources/UnitTests/Email/PROJECT.EmailManagement.Tests/TestResults/PROJECT.Service.EmailManagement.Tests.TestResults.trx'. 08:14:20.692 DEBUG: Parsed Visual Studio Unit Test - testId: d6d494be-39dc-26cd-f32d-d84059333c74 outcome: Passed, duration: 0 08:14:20.695 DEBUG: Test method PROJECT.Service.EmailManagement.Tests.PROJECT.Service.EmailManagement.Tests.EmailControllerTests.TestPost cannot be mapped to the test source file. The test will not be included. 08:14:20.696 INFO: Sensor C# Unit Test Results Import [csharpenterprise] (done) | time=22ms
I have control over updating the test names but noiticed from the logs that it is generating the wrong namespace. For example, the following is found in the logs:
Test method COMPANY.PROJECT.Tests.COMPANY.PROJECT.Tests.ApplicationSettingsTests.Properties_CanBeSet_AndRetrieved cannot be mapped to the test source file. The test will not be included.
The first part marked in bold seems to be a duplication while the test class name is not having this duplication. It looks like it is pre-fixing the assembly name, followed by the namespace, class and method name. Maybe this is a clue of what is going wrong.
would this be possible?
If not due to privacy reasons maybe you could share a reproducer project with similar test format to the ones that have the issue?
FYI we had this issue before, but with NUnit. The root cause was that the user was overriding the test name via the TestName property for parametrized tests, and that resulted in the test results file to not have the correct full name of these tests - so mapping from test results to actual code was impossible. Let me know if this rings a bell in your case.
If not it would be great to still inspect how the tests results file is encoding the test names to exclude that the problem is there.
We have the same issue for all our projects and all unit tests. It is not isolated to one specific project. Here is the code of one testing method:
public class HealthControllerTests
{
[Fact]
public void Index_ReturnsStatusCode200()
{
// Arrange
var controller = new HealthController();
// Act
var result = controller.Index();
// Assert
var statusCodeResult = Assert.IsType<StatusCodeResult>(result);
Assert.Equal(200, statusCodeResult.StatusCode);
}
}
So I managed to replicate the issue.
I tested with the SQ version that you mentioned in your first post and SQ LTA (2025.3.1).
I have the same issue with both versions.
I have 2 questions:
1 - for which SQ version were your test results working before?
2 - Is is possible that you updated some xunit package meanwhile or dotnet test? If yes could you please give me these versions too?
In my repro the issue was solved - as to map the test results back to the actual tests, the tests themselves need to be included in the analysis.
This requirement is valid since sonar-dotnet 10.4 (which is the change that altered your result after the SQ upgrade).
Could you please check if /d:sonar.dotnet.excludeTestProjects=true is set anywhere else in your analysis (server options - global or project properties) or if your test projects have <SonarQubeExclude>true</SonarQubeExclude>.
If not, could you please send me a reproducer where the results are not properly processed, but the test projects are not excluded from the analysis.
The following d:sonar.dotnet.excludeTestProjects=true was needed to be removed indeed but found that our pipelines were running the dotnet test command before the sonarscanner begin was called. By moving the dotnet test inside the sonarscanner begin and sonarscenner end block it started to work.
I believe we can close the topic. Thanks so much for your help with finding a solution.