Bla*_*ell 8 c# code-coverage xunit visual-studio visual-studio-2015
我有一个ASP.NET Core 1.0(以前称为ASP.NET 5)解决方案,包含几个类库(包)和一个ASP.NET MVC6项目.
我有一个测试库使用支持Core 1.0的新XUnit 2.0.
但是,出于某种原因,我的代码覆盖率在我正在通过的所有测试中运行时产生零结果.
默认情况下,ASP.NET Core 1.0项目由运行时内置在内存中,并且没有任何工件持久保存到磁盘.因此,在设置中,我为解决方案中的每个项目启用了"在构建时生成所有输出".现在,当我构建时,我看到pdb和dll文件正在输出到artifacts文件夹.我认为确保代码覆盖率可以在此之后工作,但仍然没有结果.
也许代码覆盖只是简单地不适用于新的.NET Core 1.0.如果有人对此有一些信息会很棒.
我可以使用此配置获得OpenCover 4.6.166的代码覆盖率:
{
"version": "1.0.0-*",
"dependencies": {
"<project under test>": "1.0.0-*",
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"xunit": "2.2.0-beta2-build3300"
},
"frameworks": {
"net451": {
"dependencies": {
"Moq": "4.5.16"
}
},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.Process": "4.1.0",
"System.Diagnostics.TraceSource": "4.0.0"
},
"imports": [
"dnxcore50",
"portable-net451+win8"
]
}
},
"testRunner": "xunit"
Run Code Online (Sandbox Code Playgroud)
}
我使用myget CI feed我的NuGet.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<!--<add key="aspnetmaster" value="https://www.myget.org/F/aspnetmaster/api/v3/index.json" />-->
<!--<add key="aspnetlatest" value="https://www.myget.org/F/aspnetvnext/api/v2" />-->
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
</packageSources>
</configuration>
Run Code Online (Sandbox Code Playgroud)
使用--infer-runtimes选项恢复依赖项:
dotnet restore --infer-runtimes
Run Code Online (Sandbox Code Playgroud)
然后在此命令行中使用OpenCover:
OpenCover.exe -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:" test ""<your project path>\project.json"" -f net451 -xml ""test\ChatLe.Repository.Test\xunit-results.xml"" -nologo -parallel none" -output:"<your coverage .xml path>" -register:user -filter:"+[*]* -[xunit*]* -[*]*Migrations.*" -returntargetcode
Run Code Online (Sandbox Code Playgroud)
注意-f net451开关很重要,它告诉dotnet使用net451框架.要覆盖netcoreapp1.0,请使用-f netcoreapp1.0.
在我的控制台输出中,我可以看到这些结果:
小智 0
我关注了这个博客,并通过 opencover 获得了一些结果,尽管我认为这是不正确的。
我需要调查为什么数字错误,如果您找到/找到了一种方法,请分享。
http://dotnetthoughts.net/measuring-code-coverage-of-aspnet-core-applications-using-opencover/
归档时间: |
|
查看次数: |
2380 次 |
最近记录: |