Search code examples
c#visual-studioreportcode-coverageopencover

Are there any open cover tools or extensions available for Visual Studio 2017?


I was trying to extract coverage report of my application using following command

OpenCover.Console.exe ^
-register:user ^
-target:"mstest.exe" ^
-targetargs:"/testcontainer:\"C:\myapp\bin\myapp.dll\" /resultsfile:\"myapp.trx\"" ^
-filter:"+[myapp*]* -[myapp.Test]* -[*]myapp.RouteConfig" ^
-mergebyhash ^
-skipautoprops ^
-output:"myapp.xml"

Then report

.\ReportGenerator.exe ^
-reports:"F:\OpenCover\myapp.xml" ^
-targetdir:"ReportGenerator"

But I'm getting the following errors when running open cover?

enter image description here

Am I doing anything wrong with command?

PS: I have already registered open cover profiler


Solution

  • I was using mstest.exe instead of vstest.console for running test cases in open cover

    Here is batch file code snippet to extract coverage report using open-cover.

    ::Note:Before running this file, make sure opencover and reportgenerator installed in your system
    ::Download and read about opencover : https://github.com/OpenCover/opencover
    ::You can read about vstest.console command line documentation here https://msdn.microsoft.com/en-us/library/ms182486.aspx
    
    ::Set your project and report location's base path here
    SET basePath=C:\MyProject
    SET targetReportDir=F:\MyProject
    SET targetHtmlReportDir=F:\MyProject\ReportGenerator
    
    ::Replace your test project Dll's path here
    SET unitTestDlls=%basePath%\Demo.BusinessData\bin\Debug\Demo.BusinessData.Test.dll %basePath%\Demo.Cache.Test\bin\Debug\Demo.Cache.Test.dll
    
    
    echo Test cases are running...
    OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"%unitTestDlls%" -filter:"+[Demo*]* -[Demo*Test]* -[Demo*Test.Core]* -[Demo*Tests]*" -output:%targetReportDir%\DemoFullReport.xml -mergebyhash
    
    
    echo Coverage report is preparing and will be saved to %targetHtmlReportDir%\Demo location
    ReportGenerator.exe -reports:"%targetReportDir%\DemoFullReport.xml" -targetdir:"%targetHtmlReportDir%\Demo"
    

    Key points to check before running this batch file

    1. Make sure vstest.console environent is setup or run in visual studio command line.
    2. Make sure, your opencover is setup and accssible through command line.
    3. Make sure opencover report generator is setup and accssible through command line.

    Thanks