While I was working on my side project Sentinel(https://github.com/mmercan/sentinel) I have several
Dotnet Core projects, I have separate docker images for testing and I used dotnet test as below.
RUN dotnet test ./Sentinel.Api.HealthMonitoring/Sentinel.Api.HealthMonitoring.sln /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=/TestResults/
They worked quite nicely and having no problem until there are more than one test projects. When I run it with multiple test projects I could only see the latest test, test coverage. When I dig into it coverage.opencover.xml file in TestResults Folder overridden by each project and last test project coverage will be sent to SonarQube. this wasn’t ideal.
When I search I find /p:MergeWith flag merge coverage of multiple projects Which could solve my problem has one problem it can only work with JSON and SonarQube expects XML
My Solution was unconventional but it worked fine for me.
The first step, I run the test and merged all test results as JSON (I added logger and results-directory to collect more info to SonarQube)
RUN dotnet test ./Sentinel.Api.HealthMonitoring/Sentinel.Api.HealthMonitoring.sln /p:CollectCoverage=true /p:CoverletOutput=/TestResults/ /p:MergeWith=/TestResults/coverage.json --logger=trx --results-directory /TestResults/
and I created a Folder named ” Empty.Tests” and Create a test Project with no test in it, I use it to convert JSON coverage results to XML
RUN dotnet test ./Sentinel.Empty.Tests/Sentinel.Empty.Tests.sln /p:CollectCoverage=true /p:MergeWith="/TestResults/coverage.json" /p:CoverletOutputFormat="opencover" /p:CoverletOutput=/TestResults/
This Merged JSON coverages and export them as XML in Opencover format
here is the Full docker test file if you interested
https://github.com/mmercan/sentinel/blob/master/Sentinel.Api.HealthMonitoring/dockerfile-linux-test
and SonarQube Result Page
https://sonarcloud.io/dashboard?id=Sentinel.Api.HealthMonitoring