2016-11-28 1113 views
2

我正尝试在ASP.NET Core上运行Xunit和Fluent断言的代码覆盖率。但是,我收到了一个我不太了解的错误消息。用OpenCover运行XUnit和FluentAssertions会给出错误信息

我的测试项目的project.json:

{ 
    "version": "1.0.0-*", 
    "testRunner": "xunit", 
    "debugType": "portable", 
    "dependencies": { 
    "xunit": "2.2.0-beta2-build3300", 
    "FluentAssertions": "4.15.0", 
    "dotnet-test-xunit": "2.2.0-preview2-build1029", 
    "ExpenseReporting": "1.0.0-*", 
    "Moq": "4.6.38-alpha" 
    }, 
    "commands": { 
    "test": "xunit.runner.dnx" 
    }, 
    "frameworks": { 
    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.0.1" 
     } 
     } 
    } 
    } 
} 

我对OpenCover命令:

OpenCover.Console.exe -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:"test "C:\Users\johndoe\Desktop\Application\ExpenseReporting.Test\project.json"" -output:coverage.xml -register:user -filter:"+[*]* -[xunit*]* -[*]*Migrations.*" 

我收到了很多错误,但都是这样的:

An System.IO.DirectoryNotFoundException occured: Could not find a part of the path 'C:\projects\fluentassertions-vf06b\Src\FluentAssertions.NET40\Execution\MSTestFramwork.cs'. 

我很清楚该目录没有找到,因为它不存在。我想知道为什么它试图在那里访问它?

+0

你有没有发现任何解决这个? – valorl

回答

0

看起来像你的project.json文件的一些问题。如果您使用的是dotnet命令,则不存在commands元素。你的project.json文件应该是这样的。

{ 
    "version": "1.0.0-*", 
    "testRunner": "xunit", 
    "dependencies": { 
     "xunit": "2.2.0-beta2-build3300", 
     "dotnet-test-xunit": "2.2.0-preview2-build1029", 
     "FluentAssertions": "4.15.0", 
     "ExpenseReporting": "1.0.0-*", 
     "Moq": "4.6.38-alpha" 
    }, 
    "frameworks": { 
     "netcoreapp1.0": { 
      "dependencies": { 
       "Microsoft.NETCore.App": { 
        "type": "platform", 
        "version": "1.0.0" 
       } 
      } 
     } 
    } 
} 

https://xunit.github.io/docs/getting-started-dotnet-core.html

下面是一个命令,它运行测试,并使用开盖获得代码覆盖率。

OpenCover.Console.exe -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:"test C:\projects\HelloWorld.Tests" -register:user -filter:"+[*]* -[xunit*]*" -output:coverage.xml -oldStyle

+1

我仍然遇到与FluentAssertions相同的错误 – Stefan

2

看起来OpenCover正在努力包括在其覆盖报告FluentAssertions的源代码。我不完全确定它为什么这样做,但我可以通过告诉OpenCover排除FluentAssertions来解决此问题。

这是过滤器,我使用:

-filter:"+[*]* -[*FluentAssertions*]*" 
+0

有趣,但添加过滤器至少可以防止错误消息显示出来。参考和使用多个过滤器:https://github.com/opencover/opencover/wiki/Usage#understanding-filters – ICantSeeSharp