MSTest无法找到assembly体

我正在使用MSTest

我使用命令mstest /testsettings:local.Testsetting /testcontainer:folder\obj\Debug\test.dll

这是输出,

运行具有以下问题:警告:测试运行部署问题:程序集或模块’Microsoft.Practices。 未找到由测试容器’test.dll’直接或间接引用的Prism。 警告:测试运行部署问题:未找到测试容器“test.dll”直接或间接引用的程序集或模块“Project.Common.dll”。 警告:测试运行部署问题:未找到测试容器“test.dll”直接或间接引用的程序集或模块“Project.Infrastructure.dll”。 警告:测试运行部署问题:程序集或模块’Microsoft.Practices。 未找到由测试容器’test.dll’直接或间接引用的Prism。

我能做些什么让MSTest运行良好。

您可以在构建服务器的GAC中安装Prism文件。

未在测试中直接使用的所有程序集都不会复制到测试文件夹。 因此,那些测试方法应该用以下属性进行修饰:

[DeploymentItem("Microsoft.Practices.Prism.dll")] 

这解决了问题,而无需将组件添加到GAC。

好。 DeploymentItem是一种解决此问题的方法。 但是,DeploymentItem有点脆弱。

这是我修复它的方法。

“当前目录”必须与DeploymentItem对齐。 我发现最好的折衷方案是将当前目录设置为.sln文件所在的位置。

这是我的文件夹结构。

 C:\SomeRootFolder\ C:\SomeRootFolder\MySolution.sln C:\SomeRootFolder\packages\ C:\SomeRootFolder\packages\MyNugetPackage.1.2.3.4\lib\net45\SomeThirdPartyDll.dll C:\SomeRootFolder\MyTestProject\MyTestProject.csproj C:\SomeRootFolder\MyTestProject\MyTestClass.cs 

MyTestClass.cs

 [TestClass] public class MyTestClass { [TestMethod] /* The DeploymentItem item below is for error ::: Warning: Test Run deployment issue: The assembly or module 'SomeDll' directly or indirectly referenced by the test container 'C:\SomeRootFolder\MyTestProject\bin\debug\MyTestProject.dll' was not found. */ /* There must be a CD (to the .sln folder) command... before the MsTest.exe command is executed */ [DeploymentItem(@".\packages\MyNugetPackage.1.2.3.4\lib\net45\SomeDll.dll")] public void MyTest() { } } 

“技巧”是对包含.sln的文件夹执行CD(更改目录)。

 REM Now the normal restore,build lines nuget.exe restore "C:\SomeRootFolder\MySolution.sln" REM the above nuget restore would create "C:\SomeRootFolder\packages\MyNugetPackage.1.2.3.4\lib\net45\SomeThirdPartyDll.dll" MSBuild.exe "C:\SomeRootFolder\MySolution.sln" /p:Configuration=Debug;FavoriteFood=Popeyes /l:FileLogger,Microsoft.Build.Engine;logfile=MySolution.Debug.Build.log REM (the below line is the trick to line up the 'current folder' with the relative path of the DeploymentItem) cd "C:\SomeRootFolder\" REM now the below will work without the annoying message, note that C:\SomeRootFolder\MyTestProject\bin\Debug\SomeThirdPartyDll.dll exists MsTest.exe /testcontainer:"C:\SomeRootFolder\MyTestProject\bin\Debug\MyTestProject.dll" /resultsfile:MyTestProject.Dll.Results.trx 

现在因为“当前目录”(CD的结果)位于“C:\ SomeRootFolder \”,DeploymentItem相对路径正常工作。

Jimminy Crickets …….这有点疯狂。

请注意,保罗泰勒在这里回答

使用自定义程序集基目录从命令行运行MsTest

对我不起作用。

最简单的方法。 只需添加

  string value = AppDomain.CurrentDomain.BaseDirectory; 

到您的代码(在测试方法的起始点)向新添加的代码添加断点并检查value变量的路径是什么。

继续测试过程,一切都成功后导航到values变量的文件夹。

您可能会看到文件夹中的所有dll。 只需复制它们和过去的软件,然后使用mstest命令行工具执行项目dll。

 set mstestPath="C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE" %mstestpath%\mstest /testcontainer:CodedUITestProject1.dll