2016-02-23 162 views
3

我開始一個新的ASP.net vNext/MVC6項目,我想用xUnit來測試它。爲什麼xUnit無法找到我的DNX測試?

我已經關注了DNX項目的instructions on the xUnit web site

當我嘗試運行在Visual Studio的測試,或者使用內置的流道或ReSharper的,我收到此錯誤信息:

Test Runner error message

如果我嘗試運行從測試命令行中,我得到這個:

 
xUnit.net DNX Runner (32-bit DNX 4.5.1) 
    Discovering: TA.Product.Tests 
    Discovered: TA.Product.Tests 
    Starting: TA.Product.Tests 
    TA.Product.Tests.Class1.FactMethodName [FAIL] 
     System.NullReferenceException : Object reference not set to an instance of an object. 
     Stack Trace: 
     D:\VS-Projects\TA.Product\src\TA.Product.Tests\Class1.cs(25,0): at TA.Product.Tests.Class1.FactMethodName() 
    Finished: TA.Product.Tests 
=== TEST EXECUTION SUMMARY === 
    TA.Product.Tests Total: 1, Errors: 0, Failed: 1, Skipped: 0, Time: 2.216s 

這是我的project.json文件:

{ 
    "version": "1.0.0-*", 
    "description": "TA.Product.Tests Class Library", 
    "authors": [ "Tim" ], 
    "tags": [ "" ], 
    "projectUrl": "", 
    "licenseUrl": "", 
    "dependencies": { 
    "TA.Product": "1.0.0-*", 
    "xunit": "2.1.0", 
    "xunit.runner.dnx": "2.1.0-rc1-build204" 
    }, 
    "commands": { 
    "test": "xunit.runner.dnx" 
    }, 
    "frameworks": { 
    "dnx451": { }, 
    "dnxcore50": { 
     "dependencies": { 
     "Microsoft.CSharp": "4.0.1-beta-23516", 
     "System.Collections": "4.0.11-beta-23516", 
     "System.Linq": "4.0.1-beta-23516", 
     "System.Runtime": "4.0.21-beta-23516", 
     "System.Threading": "4.0.11-beta-23516" 
     } 
    } 
    } 
} 

我發現this question,我的xUnit runner版本似乎與我的DNX版本RC1-Update1相匹配。

我還發現this question,說我的測試必須是公開的,他們是。

請問您有什麼想法?

+1

所以這不是一個完整的答案,但我知道R#的xunit測試運行器擴展無法運行DNX測試 - 因爲它在dll的錯誤位置查找。 Class1的第25行看起來像什麼(在'FactMethodName'方法中)? – danludwig

+0

@danludwig我不完全確定這條線是什麼,但你的觀點非常有道理。因此,R#runner找不到測試,因爲編譯器沒有發出任何輸出文件,對吧?這些都是通過aspnet5在內存中完成的。所以我實際看到的是兩個不同的問題。它看起來像我的代碼導致NullReferenceException。 –

+1

是的。第二個從命令行運行'dnx test'的程序不會崩潰,它會成功並告訴你有1個失敗的測試。您可以設置您的項目以發出輸出文件(程序集dll),但仍然R#不會在默認情況下生成它的位置。它應該使用默認的VS 2015測試資源管理器。 – danludwig

回答

1

當您運行命令行dnx test,並得到這些結果:

Finished: TA.Product.Tests 
=== TEST EXECUTION SUMMARY === 
    TA.Product.Tests Total: 1, Errors: 0, Failed: 1, Skipped: 0, Time: 2.216s 

...這實際上是一個成功的試運行。唯一的問題是你的1測試失敗。

我想,當它「崩潰」時,你試圖使用ReSharper xUnit亞軍擴展運行。該跑步者目前(從rc1)而不是與DNX項目一起工作,因爲R#在其不存在的位置查找已編譯的測試程序集。嘗試禁用resharper xUnit runner擴展並改爲從默認的Visual Studio Test Explorer運行測試。它應該工作。

然後,當您需要運行測試時,不要使用任何R#按鈕或快捷方式。改爲使用內置的VS測試按鈕&命令(或者從命令行運行dnx test,這應該會更快)。一旦你弄清楚了,你可以爲其他非DNX項目重新啓用R#xunit亞軍。

相關問題