【问题标题】:Running NUnit test without nunit.framework.dll in the same repository在同一存储库中运行没有 nunit.framework.dll 的 NUnit 测试
【发布时间】:2016-07-11 07:37:58
【问题描述】:

所以我已经用 NUnit 3.2.1 编译了我的测试 dll,我在另一个程序中使用命令“vstest.console.exe”运行如下:

var Args = "/UseVsixExtensions:true" + " " + "\"" + @"D:\path\myDllTestNunit.dll" + "\"" +
                 " " + "/TestAdapterPath:" + "\"" + @"C:\path\NUnit3TestAdapter.3.0.10\lib" + "\"" +
               " " + "/Logger:trx" + " /settings:" + "\"" + @"D:\pathRunsettings\dbci_2016_06_23_10_01_56.runsettings" + "\"";
        var cmdPath = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe";

        var proc = new Process();
        proc.StartInfo.FileName = cmdPath;
        proc.StartInfo.Arguments = Args;

        proc.StartInfo.RedirectStandardOutput = true;
        proc.StartInfo.RedirectStandardError = true;
        proc.EnableRaisingEvents = true;
        proc.StartInfo.CreateNoWindow = false;

        proc.ErrorDataReceived += proc_DataReceived;
        proc.OutputDataReceived += proc_DataReceived;
        proc.StartInfo.UseShellExecute = false;
        proc.Start();

        proc.BeginErrorReadLine();
        proc.BeginOutputReadLine();

        proc.WaitForExit();
        Console.ReadLine();

我的问题是我想使用该命令执行我的测试,但在同一目录中没有 nunit.framework.dll。我试图把这个放在 GAC 中,但我仍然遇到以下错误(已经尝试过使用 NUnit Adapter 最新版本,仍然相同):

>>> Starting test execution, please wait...
>>> Information: NUnit Adapter 3.0.10.0: Test execution started
>>>
>>> Information: Running all tests in D:\appli\statro\RSS3_BATCHES_TEST\UT\LANCE
MENT_TESTS\RSS3.Batches.Test.Nunit.Tests.dll
>>>
>>> Warning: Dependent Assembly nunit.framework of D:\appli\statro\RSS3_BATCHES_
TEST\UT\LANCEMENT_TESTS\RSS3.Batches.Test.Nunit.Tests.dll not found. Can be igno
red if not a NUnit project.
>>>
>>> Information: NUnit Adapter 3.0.10.0: Test execution complete
>>>
>>> Warning: No test is available in D:\appli\statro\RSS3_BATCHES_TEST\UT\LANCEM
ENT_TESTS\RSS3.Batches.Test.Nunit.Tests.dll. Make sure that installed test disco
verers & executors, platform & framework version settings are appropriate and tr
y again.

那么,长话短说,是否可以在没有 nunit.framework.dll 在同一目录中的情况下启动我的 nunit 测试 dll? 谢谢

【问题讨论】:

  • 为什么你想这样做?测试程序集期望能够加载nunit.framework.dll...就这么简单。
  • 好吧,我将不得不在具有多个测试的多个 dll 的多个目录上启动此命令,并且我不想在每个目录中安装 nunit.Framework.dll 以启动这些测试。所以我想把它放在别的地方(试过GAC),但似乎引用找不到它。
  • 但是您是如何构建这些测试程序集的呢?我希望构建过程能够自动包含测试程序集的所有依赖项——包括 nunit.framework.dll。
  • 是的,当然我的测试程序集引用了 GAC 中的 nunit.Framework.dll,然后我构建它,并在该程序集上启动我的命令。但是如果没有 nunit.Framework.dll 在同一个存储库中,就不可能执行这个。
  • 我会将它从 GAC 中删除,并设置 CopyLocal=true,以便它确实被自动复制。一般来说,我会尽可能避免使用 GAC——它是为了让事情变得更简单,但最终它会导致更多的 IME 问题。

标签: c# dll nunit gac nunittestadapter


【解决方案1】:

NUnit 运行器手动加载框架以支持框架的多个版本。例如,NUnit 2 和 3 测试在内部由完全不同的运行器运行。我们还支持在一次测试运行中针对多个版本的框架运行测试。

NUnit 也不附带将程序集放入 GAC 的安装,因为它不支持不同 .NET 目标的多个副本。因此,程序集加载代码从未使用 GAC 进行过测试,以后也不会。

GAC 对于团队中需要手动安装正确版本和目标才能构建 NUnit 的开发人员来说也很困难。他们还需要协调版本升级。

磁盘很便宜,使用 NuGet 并允许它按预期复制依赖项。我们都被雇用来解决业务问题,而不是与我们的构建工具作斗争;-)

【讨论】:

  • 是的,当然能够使用 NuGet 会很棒,但是编译我的 dll 并将它们安装在服务器上的自制工具仍然不支持它。所以我只好找一些其他的方法,我实际上是用复制本地的方式来尝试的。感谢您的回答
猜你喜欢
  • 1970-01-01
  • 2016-10-24
  • 2014-01-03
  • 1970-01-01
  • 2011-02-24
  • 1970-01-01
  • 1970-01-01
  • 2017-01-16
  • 1970-01-01
相关资源
最近更新 更多