Code Coverage Results Import
Code Coverage Technologies Supported
Make the most of your code coverage data with NDepend (2 minutes)
How to specify coverage results files to import in NDepend project?
Code coverage data is imported from coverage result files generated by the coverage tools.
Coverage results files can be specified from NDepend > Project Properties > Analysis > Code Coverage.
The dialog can be directly accessed from VisualStudio menu: NDepend > Coverage > Import Code Coverage Data
Code coverage result files imported might be generated by different tools. In such situation NDepend will merge data properly.
How to specify coverage results files to import in Azure DevOps / TFS extension?
If you have a test task with Code Coverage Enabled, NDepend analysis will automatically import the resulting code coverage. Results will be significantly more useful with coverage imported.
However if you are running a specific or custom task to gather code coverage with a technology different than Microsoft Visual Studio coverage you can still use the Get Coverage Files from a specified directory NDepend task option option. NDepend will be smart enough to determine for each coverage file (there can be one or many), which coverage technology has been used to generate it and how to import this data.
Why importing coverage results files?
Exclusion of code elements from coverage statistics with an attribute?
All methods and types tagged with System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute will be excluded from NDepend coverage statistics, no matter the coverage technology used.
All methods and types tagged with System.Diagnostics.DebuggerNonUserCodeAttribute or System.Diagnostics.DebuggerHiddenAttribute will be excluded from NDepend coverage statistics only for Visual Studio coverage files.
In VisualNDepend menu: Project Properties > Analysis > Code Coverage > Settings you can provide your own exclusion attribute.
See the screenshot in the previous section, there YourNamespace.ExclusionAttribute is used for example.
Visual Studio 2019, 2017, 2015, 2013, 2012 and 2010 Code Coverage
NDepend supports both Visual Studio coverage file formats:
.NET Core coverage requires <DebugType>Full</DebugType> to be set both on unit test projects and tested projects.
More information available here.
.coverage result files can be obtained with the tool VSTest.Console.exe with the /EnableCodeCoverage option, for example:
"%programfiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\VSTest.Console.exe" ^ "..\bin\netcoreapp2.1\Tests1.dll" ^ "..\bin\netcoreapp2.1\Tests2.dll" ^ /EnableCodeCoverage /InIsolation
You can manually export XML coverage files from binary coverage files from Visual Studio with this option:
To obtain code coverage from within the NDepend Azure DevOps / TFS extension, just tick the Code Coverage Enabled option in the Test task.
Just reference OpenCover xml coverage files created with OpenCover.Console.exe, or reference a directory that contains these files.
Typically OpenCover.Console.exe will be invoked this way to obtain OpenCover xml coverage files.
"%LOCALAPPDATA%\Apps\OpenCover\OpenCover.Console.exe" ^ -output:"%CD%\OpenCoverDateFile.xml" ^ -register:user ^ -target:"%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" ^ -targetargs:"UnitTestProject1\bin\Debug\UnitTestProject1.dll"
JetBrains DotCover 1.1 and above
By default DotCover outputs XML coverage file. However NDepend cannot parse the default DotCover XML coverage file. You need to configure DotCover to output NDepend XML files. This can be done this way in your DotCover configuration file:
<?xml version="1.0" encoding="utf-8"?>
Also the UI has a special option to export to NDepend:
See also this article about using TeamCity, DotCover and NDepend, by Laurent KempÃ©:
Using TeamCity integrated DotCover coverage files with NDepend
NCover 3.X and above
NDepend reads NCover v3 XML format, hence if you are using NCover v4 or above, you need to export your coverage file with v3 format as explained in this NCover documentation.
This looks like :
ncover export --project="MyProject" --execution="3/12/2017" --file="C:\Users\Support\Desktop\Report\coverage-export" --format=v3xmlIf you are using TestDriven.NET and/or NCoverExplorer.exe you can access folder that contains coverage file from the Explore Coverage Folder menu: