问题描述
我有一个ASP.NET Core 1.0(以前称为ASP.NET 5)解决方案,其中包含几个类库(包)和一个ASP.NET MVC6项目.
I have a an ASP.NET Core 1.0 (previously known as ASP.NET 5) solution with a couple of Class Library (Package)'s and an ASP.NET MVC6 project.
我有一个使用支持Core 1.0的新XUnit 2.0的测试库.
I have a test library using the new XUnit 2.0 which supports Core 1.0.
但是,由于某些原因,在所有通过的测试上运行时,我的代码覆盖率导致零结果.
However, for some reason my code coverage is producing zero results when running it on all of my tests which are passing.
默认情况下,ASP.NET Core 1.0项目由运行时在内存中构建,并且不会将任何工件持久化到磁盘中.因此,在设置中,我为解决方案中的每个项目启用了在生成时生成所有输出".现在,当我构建时,我看到pdb和dll文件正在输出到工件文件夹.我认为可以肯定的是,此后代码覆盖范围仍然适用,但仍然没有结果.
By default, ASP.NET Core 1.0 projects are built in-memory by the runtime and no artifacts are persisted to disk. So in the settings I enabled "Produce all outputs on build" for each project in the solution. Now when I build I see the pdb and dll files being output to the artifacts folder. I thought for sure code coverage would work after this, but still no results.
也许代码覆盖率仅与新的.NET Core 1.0无关.如果有人对此有一些了解,那就太好了.
Maybe code coverage just simply doens't work with the new .NET Core 1.0. If anyone has some information on this that would be great.
推荐答案
我可以使用以下配置通过 OpenCover 4.6.166 进行代码覆盖:
I'm able to get code coverage with OpenCover 4.6.166 using this configuration :
{
"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"
}
我使用myget CI馈送我的NuGet.config:
I use the myget CI feed my 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>
使用-推断运行时间选项还原依赖项:
dotnet restore --infer-runtimes
然后在此命令行中使用OpenCover:
Then use OpenCover with this command line :
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
请注意 -f net451 开关很重要,它表示对dotnet使用net451框架.要覆盖netcoreapp1.0,请使用 -f netcoreapp1.0 .
Note the -f net451 switch is important, it says to dotnet to use the net451 framework. To cover netcoreapp1.0 use -f netcoreapp1.0.
在控制台输出中,我可以看到那些结果:
In my console output, I can see those result :
这篇关于VS2015代码覆盖率不适用于ASP.NET Core 1.0(以前称为ASP.NET 5)中的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!