使用xUnit测试打开封面以了解天蓝色功能

时间:2018-10-04 08:37:55

标签: code-coverage opencover

我有一个包含Azure功能实现的项目。我已经在同一解决方案下使用xUnit作为另一个项目创建了单元测试。我在解决方案级别添加了Powershell脚本以运行opencover exe。但是脚本给出了错误消息“ OpenCover.Console.exe:无法解析指定的框架版本'2.0'”。如何使用开放式封皮获得相同的代码覆盖率。我的文件夹结构是

--PM(folder)
  --PM.sln
  --PM(folder)
  --PMTests(folder)
  --TestsAndCoverage.ps1

我的TestsAndCoverage.ps1具有以下内容。

$testProjects = "PMTests"

# Get the most recent OpenCover NuGet package from the dotnet nuget packages
$nugetOpenCoverPackage = Join-Path -Path $env:USERPROFILE -ChildPath "\.nuget\packages\OpenCover"
$latestOpenCover = Join-Path -Path ((Get-ChildItem -Path $nugetOpenCoverPackage | Sort-Object Fullname -Descending)[0].FullName) -ChildPath "tools\OpenCover.Console.exe"
# Get the most recent OpenCoverToCoberturaConverter from the dotnet nuget packages
$nugetCoberturaConverterPackage = Join-Path -Path $env:USERPROFILE -ChildPath "\.nuget\packages\OpenCoverToCoberturaConverter"
$latestCoberturaConverter = Join-Path -Path (Get-ChildItem -Path                 
$nugetCoberturaConverterPackage | Sort-Object Fullname -Descending)[0].FullName -ChildPath "tools\OpenCoverToCoberturaConverter.exe"

If (Test-Path "$PSScriptRoot\OpenCover.coverageresults"){
Remove-Item "$PSScriptRoot\OpenCover.coverageresults"
}

If (Test-Path "$PSScriptRoot\Cobertura.coverageresults"){
Remove-Item "$PSScriptRoot\Cobertura.coverageresults"
}

& dotnet restore

$testRuns = 1;
foreach ($testProject in $testProjects){
# Arguments for running dotnet
$dotnetArguments = "xunit", "-xml `"`"$PSScriptRoot\testRuns_$testRuns.testresults`"`""

"Running tests with OpenCover"
& $latestOpenCover `
    -register:user `
    -target:dotnet.exe `
    -targetdir:$PSScriptRoot\$testProject `
    "-targetargs:$dotnetArguments" `
    -returntargetcode `
    -output:"$PSScriptRoot\OpenCover.coverageresults" `
    -mergeoutput `
    -oldStyle `
    -excludebyattribute:System.CodeDom.Compiler.GeneratedCodeAttribute `
    "-filter:+[Sample*]* -[*.Tests]* -[*.Tests.*]*"

    $testRuns++
}

"Converting coverage reports to Cobertura format"
& $latestCoberturaConverter `
-input:"$PSScriptRoot\OpenCover.coverageresults" `
-output:"$PSScriptRoot\Cobertura.coverageresults" `
"-sources:$PSScriptRoot"

0 个答案:

没有答案