【问题标题】:MSTest cannot find the assemblyMSTest 找不到程序集
【发布时间】:2011-07-25 18:22:00
【问题描述】:

我使用的是 MSTest

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

这是输出,

Run 存在以下问题: 警告:测试运行部署问题: 组件或模块 '微软实践。棱镜'直接 或被测试间接引用 找不到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 'Project.Common.dll' 直接或 测试间接引用 找不到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 'Project.Infrastructure.dll' 直接 或被测试间接引用 找不到容器“test.dll”。 警告:测试运行部署问题: 组件或模块 '微软实践。棱镜'直接 或被测试间接引用 找不到容器“test.dll”。

我该怎么做才能使 MSTest 运行良好。

【问题讨论】:

    标签: c# unit-testing mstest vs-unit-testing-framework


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      这无需将程序集添加到 GAC 即可解决问题。

      【讨论】:

      • 我遇到了类似的错误,该项目正在 Jenkins 中构建。如何在 Jenkins 中使用您的解决方案?警告:测试运行部署问题:测试容器 'd:\alm_jenprodslave_1\workspace\total fund\alm\otpp.pivot.core\otpp.pivot.core.model 直接或间接引用的程序集或模块 'zlib.net' .test\bin\debug\otpp.pivot.core.model.test.dll' 没有找到。
      • 当程序集不在 GAC 中时,这种方法(仅使用名称)是否确实有效?我遇到了问题,不得不输入完整的文件路径。
      【解决方案3】:

      好的。 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.......这有点疯狂。

      注意,这里是 Paul Taylor 的回答

      Running MsTest from the command line with a custom assembly base directory

      对我不起作用。

      【讨论】:

        【解决方案4】:

        最简单的方法。 只需添加

         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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2010-10-19
          • 1970-01-01
          • 2011-09-23
          • 2019-06-06
          • 2011-03-20
          • 2011-03-02
          相关资源
          最近更新 更多