I want to measure the Code Coverage of my XUnit-Tests in an ASP.NET Core application. The Tooling for .NET Core in Visual Studio 2015 is preview 2 and code coverage does not work so far.
The blog post http://dotnetthoughts.net/measuring-code-coverage-of-aspnet-core-applications-using-opencover/ from February shows a workaround by using the command line of open cover. I am looking for a more integrated way inside of Visual Studio.
Has anybody heard of a better / more integrated way of measuring Code Coverage in combination with XUnit ?
On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.
Code coverage is to determine to what portion of your project code is being tested by Unit testing; you can use the code coverage feature of Visual Studio. Code coverage is an option, when you run the test methods, using Test Explorer. On the Test menu, choose Analyze Code Coverage.
Code Coverage Analysis is simply a structural testing technique to measure how many lines/blocks/arcs of your implemented code are executed while the automated tests are running. Its analysis gives you a quick, automated and accurate quality & coverage measurement for test plans.
Add the NuGet package Microsoft.CodeCoverage 1.0.1 to your project.json
.
I am working on Template for Asp.NET
and right now I am working on Unit Tests so I saw your post. You could see project/configuration here.
Disclaimer: These steps were given from Measuring ASP.NET Core Coverage with OpenCover - DotNetThoughts.
Even though the poster says about this site, I thought it would still be best to have these steps here for prosperity.
NOTE: These instructions while tailored to a windows operating system, should easily work for any O/S supported by OpenCover and ReportGenerator.
@echo off
SET dotnet="C:\Program Files\dotnet\dotnet.exe"
SET opencover="C:\Program Files (x86)\OpenCover\OpenCover.Console.exe"
SET reportgenerator="C:\Program Files (x86)\OpenCover\ReportGenerator\ReportGenerator.exe"
SET targetargs="test"
SET filter="+[*]NAMESPACE.* -[*.Test]* -[xunit.*]* -[FluentValidation]*"
SET coveragefile=Coverage.xml
SET coveragedir=Coverage
REM Run code coverage analysis
%opencover% -oldStyle -register:user -target:%dotnet% -output:%coveragefile% -targetargs:%targetargs% -filter:%filter% -skipautoprops -hideskipped:All
REM Generate the report
%reportgenerator% -targetdir:%coveragedir% -reporttypes:Html;Badges -reports:%coveragefile% -verbosity:Error
REM Open the report
start "report" "%coveragedir%\index.htm"
+[*]NAMESPACE.*
as many times as needed for each namespaceIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With