2016-11-28 1092 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