简体   繁体   中英

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.

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
    }
}

In a brand new solution that includes

  • An ASP.NET 5 Preview Template Empty project
  • A MS Test Unit Test project

Running Test -> Analyze Code Coverage - All Tests

DOES successfully complete, but it only shows code coverage for the unit test project. In addition, as it seems like you may have noticed, you cannot add a reference for your vNext project to your unit test project and also that xUnit is the only currently supported test project framework .

I think that it is safe to assume that as it stands today, yes, these tools are "broken" for vNext projects since they don't run off of the xunit.runner.dnx runner.

Interestingly enough, that same documentation does state that you can run xunit.runner.dnx tests from the VS Test Runner so it would seem that this type of issue is, at the very least, on their radar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM