简体   繁体   English

MSTest无法找到装配体

[英]MSTest cannot find the assembly

I was using MSTest 我在使用MSTest

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

and this is the output, 这是输出,

Run has the following issue(s): Warning: Test Run deployment issue: The assembly or module 'Microsoft.Practices. 运行具有以下问题:警告:测试运行部署问题:程序集或模块'Microsoft.Practices。 Prism' directly or indirectly referenced by the test container 'test.dll' was not found. 未找到由测试容器'test.dll'直接或间接引用的Prism。 Warning: Test Run deployment issue: The assembly or module 'Project.Common.dll' directly or indirectly referenced by the test container 'test.dll' was not found. 警告:测试运行部署问题:未找到测试容器“test.dll”直接或间接引用的程序集或模块“Project.Common.dll”。 Warning: Test Run deployment issue: The assembly or module 'Project.Infrastructure.dll' directly or indirectly referenced by the test container 'test.dll' was not found. 警告:测试运行部署问题:未找到测试容器“test.dll”直接或间接引用的程序集或模块“Project.Infrastructure.dll”。 Warning: Test Run deployment issue: The assembly or module 'Microsoft.Practices. 警告:测试运行部署问题:程序集或模块'Microsoft.Practices。 Prism' directly or indirectly referenced by the test container 'test.dll' was not found. 未找到由测试容器'test.dll'直接或间接引用的Prism。

What can i do so MSTest can run well. 我能做什么让MSTest运行良好。

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

All assemblies that are not used directly in test will not be copied to test folder. 未在测试中直接使用的所有程序集都不会复制到测试文件夹。 Therefor, those test methods should be decorated with attribute like: 因此,那些测试方法应该用以下属性进行修饰:

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

This solves the problem without adding the assembly to the GAC. 这解决了问题,而无需将组件添加到GAC。

Ok. 好。 The DeploymentItem is a way to fix this. DeploymentItem是一种解决此问题的方法。 However, DeploymentItem is a little fragile. 但是,DeploymentItem有点脆弱。

Here is how I fixed it. 这是我修复它的方法。

The "current directory" has to line up with the DeploymentItem. “当前目录”必须与DeploymentItem对齐。 The best compromise I found would be to set the current directory to where the .sln file is. 我发现最好的折衷方案是将当前目录设置为.sln文件所在的位置。

Here is my folder structure. 这是我的文件夹结构。

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 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()
    {
    }
}

The "trick" is to do a CD (change directory) to the folder that houses the .sln. “技巧”是将CD(更改目录)写入包含.sln的文件夹。

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

Now because the "current directory" (the result of the CD) is at "C:\\SomeRootFolder\\", the DeploymentItem relative path works correctly. 现在因为“当前目录”(CD的结果)位于“C:\\ SomeRootFolder \\”,DeploymentItem相对路径正常工作。

Jimminy Crickets.......that is a little nutsy. Jimminy Crickets .......这有点疯狂。

Note, the Paul Taylor answer here 请注意,保罗泰勒在这里回答

Running MsTest from the command line with a custom assembly base directory 使用自定义程序集基目录从命令行运行MsTest

did not work for me. 不适合我。

easiest way. 最简单的方法。 Just add 只需添加

 string value = AppDomain.CurrentDomain.BaseDirectory;

to your code (at the start point of your test method) Add a breakpoint to the newly added code and check what is the path of value variable. 到您的代码(在测试方法的起始点)向新添加的代码添加断点并检查value变量的路径是什么。

continue the test process and after everything get success navigate to the folder of values variable. 继续测试过程,一切都成功后导航到values变量的文件夹。

You might see all the dlls inside the folder. 您可能会看到文件夹中的所有dll。 Just copy them and past ware ever you want and execute the project dll using mstest command line tool. 只需复制它们和过去的软件,然后使用mstest命令行工具执行项目dll。

set mstestPath="C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"

%mstestpath%\mstest /testcontainer:CodedUITestProject1.dll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM