在 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。因此,我收到类似“c:\MyTestRunner\bin\debug\MyTests.dll”之类的 FileNotFoundException。
如何强制它在不同的目录中查找 dll?
I need to run NUnit tests programmatically in a console app. Using NUnit's nunit-console.exe is not an option. My current code is:
var testRunner = new SimpleTestRunner();
var package = new TestPackage("MyTests.dll", new List<string> { ("c:\MyTests\MyTests.dll" });
testRunner.Load(package);
When I call Load, NUnit looks for the dll in the current process's directory. So I get a FileNotFoundException for something like "c:\MyTestRunner\bin\debug\MyTests.dll".
How can I force it to look for the dll in a different directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定它如何与 NUnit 的
SimpleTestRunner()
一起使用,但使用RemoteTestRunner()
对我来说效果很好:确保
nunit.framework .dll
库位于测试程序集所在的文件夹中。尝试一下
RemoteTestRunner()
;)I'm not sure how it would work with NUnit's
SimpleTestRunner()
but using theRemoteTestRunner()
instead works fine for me:Make sure, the
nunit.framework.dll
library is in the the folder with your test assembly.Give the
RemoteTestRunner()
a try ;)你可以改变当前目录
更新:
看来这不是那么简单。
我环顾四周,有一篇 文章 和 < a href="https://stackoverflow.com/questions/1412235/how-do-you-instruct-nunit-to-load-an-assembles-dll-config-file-from-a-specific-d">堆栈关于这个问题的问题。
希望有帮助
You can change the current directory
Update:
It seems this is not so simple.
I`v looked around, there is an article and stack question on this issue.
Hope it helps
我的理解是标准 nunit-console.exe 在第二个应用程序域中运行其测试。这样它就可以将 AppDomainSetup.ApplicationBase 属性设置为所有 DLL 所在的目录。它还允许测试套件选择拥有自己的 MyTests.dll.config 副本。
我不熟悉 NUnit 源代码,快速浏览并没有发现任何可以设置第二个应用程序域的明显帮助程序类。然而,不应该有任何异常:创建一个带有更改的
ApplicationBase
属性的AppDomainSetup
;创建一个新的AppDomain
;在该应用程序域内创建您的SimpleTestRunner
;并像您已经做的那样调用Load
。My understanding is that the standard nunit-console.exe runs its tests in a second app domain. This way it can set the
AppDomainSetup.ApplicationBase
property to the directory in which all the DLLs are located. It also allows the test suite to optionally have its own copy of MyTests.dll.config.I'm not familiar with the NUnit source code, and a quick browse doesn't reveal any obvious helper classes that can set up a second app domain. However there shouldn't be anything out of the ordinary: create an
AppDomainSetup
with an alteredApplicationBase
property; create a newAppDomain
; create yourSimpleTestRunner
inside that app domain; and callLoad
like you're doing already.