运行NUnit的测试在C#控制台应用程序 [英] Running NUnit Tests In a C# Console App

查看:95
本文介绍了运行NUnit的测试在C#控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

当我呼叫负载,NUnit的查找在当前进程的目录下的DLL所以我得到一个FileNotFoundException异常的东西,如C:\MyTestRunner\bin\debug\MyTests.dll。

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".

我怎样才能迫使它看在不同的目录中的dll?

How can I force it to look for the dll in a different directory?

推荐答案

我不知道它将如何一起工作的NUnit的 SimpleTestRunner(),但使用 RemoteTestRunner(),而不是正常工作对我来说:

I'm not sure how it would work with NUnit's SimpleTestRunner() but using the RemoteTestRunner() instead works fine for me:

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

确认中, nunit.framework.dll中库与你的测试组件的文件夹。

Make sure, the nunit.framework.dll library is in the the folder with your test assembly.

输入 RemoteTestRunner()一试;)

这篇关于运行NUnit的测试在C#控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆