2011-11-10 18 views
8

我試圖讓MSTest.exe運行,它似乎像testcontainer沒有被正確讀取;而我的測試全部在Visual Studio中的所有配置環境中成功運行。MSTest.exe不能複製所有需要的項目DLLs?

我使用的命令是:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe" /nologo /usestderr /testSettings:"C:\temp\MyProject\Sources\MyProject\Local.testsettings" /searchpathroot:"C:\temp\MyProject\Binaries" /resultsfileroot:"C:\temp\MyProject\TestResults" /testcontainer:"C:\temp\MyProject\Binaries\MyProject.Services.Server.UnitTests.dll" 

testcontainer項目中的項目引用是這樣的:

<ItemGroup> 
    <ProjectReference Include="..\..\Services\MyProject.Services.Server\MyProject.Services.Server.csproj"> 
     <Project>{92EC1999-CC0C-47DD-A4D6-17C3B1233C50}</Project> 
     <Name>MyProject.Services.Server</Name> 
    </ProjectReference> 
    <ProjectReference Include="..\..\SvcConfiguration\MyProject.ServiceConfiguration.Interfaces\MyProject.ServiceConfiguration.Interfaces.csproj"> 
     <Project>{8E2E7BA9-75DB-458E-A184-AC1030EAD581}</Project> 
     <Name>MyProject.ServiceConfiguration.Interfaces</Name> 
    </ProjectReference> 
    <ProjectReference Include="..\..\SvcConfiguration\MyProject.ServiceConfiguration.Services\MyProject.ServiceConfiguration.Services.csproj"> 
     <Project>{39514766-23A8-45DB-96EA-B6B4D9C8B086}</Project> 
     <Name>MyProject.ServiceConfiguration.Services</Name> 
    </ProjectReference> 
</ItemGroup> 

無論是ServiceConfiguration.Interfaces也不ServiceConfiguration.Services DLL被置入TestResults中的Out文件夾。

項目GUID在引用和引用項目之間確實匹配。

有什麼,我在命令行中失蹤?

+0

我還沒有找到選項 「/ searchpathroot」 的[文件]中(http://msdn.microsoft.com/en-us/library/ms182489(V = VS.100)的.aspx)。 – Andreas

回答

4

您可以使用測試設置文件明確指定文件拷貝到test目錄。您可以在Visual Studio中創建多個測試設置文件,以便您可以從VS運行一個,另一個用於從MSTest運行,另一個用於服務器CI構建,等等。請參閱此處瞭解更多信息:Create Test Settings to Run Automated Tests from Visual Studio

使用/testsettings:<filename>選項可在命令行中指定它。

最初讓人困惑的是默認情況下,MSTest的「當前目錄」不是MSTest啓動目錄,而是測試結果的Out文件夾。

如前所述,MSTest不能正確推斷所有使用的程序集,如果您沒有直接引用,它將不會複製程序集。也就是說,Visual Studio在其構建中也有類似的行爲,所以很多人通過添加虛假代碼引用來解決這個問題 - 一個糟糕的解決方案 - 我不推薦它。

但是,原生DLL更有問題,我發現在測試配置(測試設置)中顯式複製它們對它們起作用,就像託管程序集一樣。

+0

如何在測試設置中配置這些原生DLL? – sebas2day

1

無論它進入Out還是構建區域取決於不同的因素,但是,對於仍然無法正常工作的情況,您可以使用DeploymentItem「hack」,或者調整runsettings文件。

嘗試尋找這個答案:https://stackoverflow.com/a/33344573/2537017

相關問題