Hi team,
I am encountering a problem to get test coverage data to the associated sonar project. The unit tests are performed and the coverage.opencover.xml file generated has coverage summary in it but for some reason sonar is not picking that up. The path is correctly set in the github workflow sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml".
When I went through some community posts, I came to kown that test files are not taken into consideration and checking the logs I found this:
INFO: Coverage Report Statistics: 95 files, 0 main files, 0 main files with coverage, 95 test files, 0 project excluded files, 0 other language files.
WARN: The Code Coverage report doesn't contain any coverage data for the included files. Troubleshooting guide: https://community.sonarsource.com/t/37151
But I am unable to troubleshoot why the main files count is zero. Iam not using sonar-project.properties file so it is picking the default properties from:
Actually for sonar scan we are using a reusable workflow, for other projects the main files are being picked as per the Coverage Report Statistics but not for this though they have same workflow and repository structure. So what could be reasons for not picking up main files? Is it the only reason for this issue? The project in sonar says the LOC used is 53 lines that too yaml files which is confusing again.
Please help me out in this and let me know if additional info is needed. Thanks in advance for the support.
Hi Colin,
Is sonar.sources and sonar.tests not supported for .NET now? I have tried to explicitly mention my source folder and test folder as my src files are detected as test files in this project. But I get the following warning!
sonar.sources and sonar.tests never had a real impact on the Scanner for .NET.
Those properties are automatically inferred from your solution/project structure.
You can use sonar.exclusions and sonar.test.exclusions to refine the scope of the analysis if you need to.
This message was added to make it clearer that setting those properties does not have any effect.
Colin is right to point you to the other thread. The message you see here indicate that all 95 files we found have been identified as part of your tests, and thus cannot be considered for coverage.
The question then becomes:
what is your project structure?
why are all your files categorized as tests?
Do you, by any chance, have a package reference to a test framework in your main code?
Thanks for those inputs Denis. I have checked the .csproj in the src folder and found reference of a unit test library FluentAssertions .Removed that and now those 95 files in src are considered as main files instead of test files.