c# - 在 C# 控制台应用程序中运行 NUnit 测试

标签 c# nunit

我需要在控制台应用程序中以编程方式运行 NUnit 测试。使用 NUnit 的 nunit-console.exe 不是一个选项。我当前的代码是:

var testRunner = new SimpleTestRunner();
var package = new TestPackage("MyTests.dll", new List<string> { ("c:\MyTests\MyTests.dll" });
testRunner.Load(package);

当我调用 Load 时,NUnit 在当前进程的 目录中查找 dll。所以我得到一个 FileNotFoundException,比如“c:\MyTestRunner\bin\debug\MyTests.dll”。

我怎样才能强制它在不同的目录中寻找 dll?

最佳答案

我不确定它如何与 NUnit 的 SimpleTestRunner() 一起工作,但使用 RemoteTestRunner() 对我来说效果很好:

TestPackage testPackage = new TestPackage(@"C:\YourProject.Tests.dll");
RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
remoteTestRunner.Load(testPackage);
TestResult result = remoteTestRunner.Run(new NullListener());

确保 nunit.framework.dll 库位于测试程序集所在的文件夹中。

试试 RemoteTestRunner() ;)

关于c# - 在 C# 控制台应用程序中运行 NUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1882514/

相关文章:

c# - 如何延长音频合成器的时间长度?

c# - IIS 托管 Web 核心托管 ASP.NET MVC

c# - TDD 中的命名测试与单元测试命名

c# - 使用 C++ 中的引用从 C# 错误调用 C++ 代码

c# - 如何在 .net 中生成 UTF-8 字符集中的所有字符

c# - MongoDB:处理游标

c# - NUnit 是 Selenium 测试的错误选择吗?

c# - 最小起订量 - 模拟 MVC Controller 的 Response.Cookies.Clear()

c# - 如何在使用 NUnit 或 XUnit 时将参数传递给 dotnet test 命令

c# - 检查对象时 NUnit Has.Member 失败