2

I have a Windows service written in .net framework 4.6. I'm trying to run Sonar analysis for this service. My requirement is to generate both code coverage result and Unit test case report either by using MStest.exe or vstest.console.exe. I have written test cases using MStest for my service.

Using MSTest, I have written the below command:

MSTest /testcontainer:.\SolutionTests\bin\Release\SolutionTests.dll /resultsfile:"C:\SonarQube\Solution.trx"

Using vstest.console.exe, I have written the below command:

vstest.console.exe SolutionTests\bin\Release\SolutionTests.dll /Enablecodecoverage /Logger:trx;LogFileName="C:\SonarQube\Solution.trx"

In both the cases only Unit test report is generated (.trx file) as I have set the filename explicitly in the command.

Is there any way I can generate .coverage file as well, with in the same command by adding other parameters. I read in few articles which said MSTest command generates both the reports (result.trx and data.coverage), but no where it is written the exact command how to do it. I ran the above command, it did not generate data.coverage file for me.

halfer
  • 19,824
  • 17
  • 99
  • 186
CrazyCoder
  • 2,194
  • 10
  • 44
  • 91

1 Answers1

0

This can be achieved using a package called Coverlet. Basically you can define the output format of the tests and generate the .trx file for Bamboo. The command will look something like:

executable test --logger "trx;LogFileName=testResults.trx"  /p:CollectCoverage=true /p:CoverletOutputFormat=preferredformat.

Check out the documentation for how to specifically integrate with VSTest.

Wesley Rolnick
  • 871
  • 4
  • 11
  • Thanks a lot for the reply. But according to the documentation, thus tool is used for dotnet core applications. I have a dotnet framework application in which I have used MSTest to write testcases. – CrazyCoder Nov 02 '19 at 06:31
  • @CrazyCoder: It supports framework and core. I've used it for both and the main documentation page specifically calls out it can be used on both. You can integrate with VSTest or MSBuild for the command line build. – Wesley Rolnick Nov 02 '19 at 14:17