Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code Coverage obsolete with vNext projects?

Because the code coverage utilities baked into Visual Studio (vstest.console.exe & codecoverage.exe) analyze binaries, such as .dll and .exe files, will these tools still work with vNext projects (since they don't generate binaries)?

I'm trying to run code coverage on a solution with vNext class libraries, but the only info I've been able to generate is for the xUnit .dll files and not my projects.

like image 371
zacran Avatar asked May 23 '26 06:05

zacran


1 Answers

Our team is able to generate a code coverage file for vNext solutions using OpenCover. This requires a bit of overhead as OpenCover analyzes on a project by project basis so you'll need to write a script to cycle through the projects in your solution, run OpenCover, then merge the coverage files.

Here's an example of what we're doing in the script in case anyone wants to replicate it:

We're looping through each project and calling both the DNX engine and OpenCover to generate coverage for that project.

foreach($projectFile in $projectFiles)
{
    $project=$projectFile.Directory.Name

    $buildCommands=$buildCommands+$projectFile.Directory.FullName
    $testPoject = //Path//To//Test//Projects
    if(Test-Path $testPoject)
    {
        _Verbose "$testPoject exists for $project"
        $testCommand = "$OpenCoverUtil -register:user ""-excludebyfile:*\*.gen.cs"" ""-target:$DnxPath\dnx.exe "" ""-targetargs: $testPoject\project.json test"" ""-output:$Outpath\CS\$project.coverage.xml"" -skipautoprops -returntargetcode -filter:""+[$project*]*"""
        _Verbose $testCommand
        $testCommands=$testCommands+$testCommand
    }
}
like image 179
zacran Avatar answered May 25 '26 22:05

zacran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!