Viewing Code Coverage Results outside of Visual studio
Asked Answered
C

7

29

I've got some unit tests, and got some code coverage data. Now, I'd like to be able to view that code coverage data outside of visual studio, say in a web browser. But, when I export the code coverage to an xml file, I can't do anything with it. Are there readers out there for this? Do I have to write an xml parser and then display it how I want it (seems like a waste since visual studio already does this.) Seems kinda silly to have to take a screenshot of my code coverage results as my "report" Suggestions?

Cooler answered 22/7, 2009 at 18:18 Comment(0)
E
14

This tool https://github.com/danielpalme/ReportGenerator quickly generate Html reports from coverage file. Works quite well and does not require complex activities, can be easily included in the build process.

Elasticity answered 6/3, 2013 at 10:0 Comment(0)
M
4

There is this tool called Visual Coverage (https://github.com/jsargiot/visual-coverage). It takes a .coverage file as input and can export it to clover or html.

The page on github shows how to execute and if you're curious you can take a look at the code...

Mixture answered 29/9, 2012 at 19:44 Comment(1)
Be aware that visual-coverage doesn't output correct values for C++ projectsUnderwood
B
2

You can use the tool NDepend and visualize code coverage results imported from NCover, dotCover or Visual Studio coverage. The tool can show code coverage vs. lines of code in a colored treemap. This feature is especially useful to browse at a glance which portion of code is well covered or not by tests.

NDepend colored treemap code coverage vs. lines of code

You can also write and apply continuously code rules written over LINQ queries (CQLinq) like:

From now, all types added or refactored should be 100% covered by tests

// <Name>From now, all types added or refactored should be 100% covered by tests</Name>
warnif count > 0 from t in JustMyCode.Types where

  // Match methods new or modified since Baseline for Comparison...
  (t.WasAdded() || t.CodeWasChanged()) &&

  // ...that are not 100% covered by tests
  t.PercentageCoverage < 100

  let methodsCulprit = t.Methods.Where(m => m.PercentageCoverage < 100)

select new { t, t.PercentageCoverage, methodsCulprit }

...or also:

The panel Search by Coverage can generate such Code Query over LINQ, and displays instantly the matched code elements:

Search methods by coverage

Also, the tool can build a HTML/javascript reports that will show code rules violated or code queries results.

Bacteriostat answered 19/10, 2010 at 13:4 Comment(0)
L
2

Now you can use the tool of dotnet for generate the report in html

dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator
"-reports:Path\To\TestProject\TestResults\{guid}\coverage.cobertura.xml"
"-targetdir:coveragereport"
-reporttypes:Html

Source: https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-code-coverage?tabs=linux#generate-reports

Lauretta answered 26/4, 2021 at 1:50 Comment(0)
F
0

I can't speak for the content of the exported XML, but I'd expect it contain your coverage data as a summary.

The usual thing to do with XML data like this if you want to see it in a web browser page is to convert it to HTML by writing and running a custom XSLT script. This will presumably get you HTML text and tables containing your data.

If you want to see the coverage data as decorations imposed on the source code, I think you have a much harder problem.

Fatigue answered 25/7, 2009 at 9:39 Comment(0)
H
0

Might help: you can open all the coverage data in the Code Coverage Results pane and copy&paste it to Excel...

Hypognathous answered 5/4, 2012 at 8:44 Comment(2)
This doesn't apply to Visual Studio Professional, where Code Coverage feature is not includedEnosis
Was that a requirement?Flump
F
-1

I use NCover to do all my code coverage and you have the ability to export the results quite easily

Florescence answered 22/7, 2009 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.