Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MSTest找不到程序集_C#_Unit Testing_Mstest_Vs Unit Testing Framework - Fatal编程技术网

C# MSTest找不到程序集

C# MSTest找不到程序集,c#,unit-testing,mstest,vs-unit-testing-framework,C#,Unit Testing,Mstest,Vs Unit Testing Framework,我在使用MSTest 我使用命令mstest/testsettings:local.Testsetting/testcontainer:folder\obj\Debug\test.dll 这就是输出 运行时出现以下问题: 警告:测试运行部署问题: 组件或模块 'Microsoft.Practices。棱镜直接 或被测试间接引用 未找到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 “Project.Common.dll”直接或 被测试间接引用 未找到容器“test.dll”。

我在使用MSTest

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

这就是输出

运行时出现以下问题: 警告:测试运行部署问题: 组件或模块 'Microsoft.Practices。棱镜直接 或被测试间接引用 未找到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 “Project.Common.dll”直接或 被测试间接引用 未找到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 直接使用“Project.Infrastructure.dll” 或被测试间接引用 未找到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 'Microsoft.Practices。棱镜直接 或被测试间接引用 未找到容器“test.dll”


我该怎么做才能使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相对路径工作正常

吉米蟋蟀……这有点疯狂

注意,这里是Paul Taylor的答案

不适合我。

最简单的方法。 加上

 string value = AppDomain.CurrentDomain.BaseDirectory;
到您的代码(在测试方法的起点) 向新添加的代码添加断点,并检查
value
变量的路径

继续测试过程,一切成功后,导航到
values
variable文件夹

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

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

%mstestpath%\mstest /testcontainer:CodedUITestProject1.dll

我得到了一个类似的错误,该项目正在詹金斯建造。如何在Jenkins中使用您的解决方案?警告:测试运行部署问题:未找到测试容器“d:\alm\u jenprodsave\u 1\workspace\total fund\alm\otpp.pivot.core\otpp.pivot.core.model.Test\bin\debug\otpp.pivot.core.model.Test”直接或间接引用的程序集或模块“zlib.net”。是否使用此方法(仅使用名称)当总成不在GAC内时,肯定能工作吗?我有问题,不得不把完整的文件路径,而不是。