We are building c# products with NUnit tests. On the main sonarcloud screen for our project, we have code coverage reported, so I assume we have unit test execution configured and running correctly:
However, if I create a new PR, it shows 0% coverage - I created a branch which has a class with 2 new methods, one tested and one not, in order to prove out a 50% new code coverage rate:
The test which runs against one of the methods in the test class is definitely executing as I have an extra test in the count (was previously 94, is now 95):
I have noticed this in the SonarCloudAnalyze output:
*INFO: Parsing the OpenCover report D:\a\_temp\VssAdministrator_fv-az454-112_2022-03-23_15_40_27.trx*
**WARN: Could not import coverage report 'D:\a\_temp\VssAdministrator_fv-az454-112_2022-03-23_15_40_27.trx' because 'Missing root element <CoverageSession> in D:\a\_temp\VssAdministrator_fv-az454-112_2022-03-23_15_40_27.trx at line 2'. Troubleshooting guide: https://community.sonarsource.com/t/37151**
*INFO: Parsing the Visual Studio coverage XML report D:\a\_temp\d25f7b86-f8f4-4aba-9f75-776481c8a656\VssAdministrator_fv-az454-112_2022-03-23.15_40_24.coveragexml*
*INFO: Adding this code coverage report to the cache for later reuse: D:\a\_temp\d25f7b86-f8f4-4aba-9f75-776481c8a656\VssAdministrator_fv-az454-112_2022-03-23.15_40_24.coveragexml*
*INFO: Coverage Report Statistics: 35 files, 30 main files, 30 main files with coverage, 5 test files, 0 project excluded files, 0 other language files.*
This is the only thing I can think of which could be causing the issue - but if it’s causing it for new code, how would we be showing any coverage at all? Any help would be greatly appreciated thank you
How have you configured the passing of analysis reports (how is sonar.cs.opencover.reportsPaths and any other relevant analysis parameters configured)?
Have you checked the coverage report (independently of SonarQube) to see if it shows these lines as covered?
extraProperties: |
# Additional properties that will be passed to the scanner,
# Put one key=value per line, example:
# sonar.exclusions=**/*.bin
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/*.trx
.trx files are Test Result files, so passing these to sonar.cs.opencover.reportsPath is doing… nothing. It looks like the pipeline is automatically picking up the .coveragexml file:
INFO: Parsing the Visual Studio coverage XML report D:\a\_temp\d25f7b86-f8f4-4aba-9f75-776481c8a656\VssAdministrator_fv-az454-112_2022-03-23.15_40_24.coveragexml
This file you should be able to open pretty easily as it’s just an XML file.