如何从 C# 代码运行 NUnit 测试
我正在尝试编写一个简单的方法来接收文件并使用 NUnit 运行它。 我设法使用 NUnit 的源代码构建的代码不起作用:
if(openFileDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
var builder = new TestSuiteBuilder();
var testPackage = new TestPackage(openFileDialog1.FileName);
var directoryName = Path.GetDirectoryName(openFileDialog1.FileName);
testPackage.BasePath = directoryName;
var suite = builder.Build(testPackage);
TestResult result = suite.Run(new NullListener(), TestFilter.Empty);
问题是我不断收到 builder.Build 抛出的异常,指出未找到程序集。
我缺少什么? 是否有其他方法可以从代码运行测试(不使用 Process.Start)?
I'm trying to write a simple method that receives a file and runs it using NUnit.
The code I managed to build using NUnit's source does not work:
if(openFileDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
var builder = new TestSuiteBuilder();
var testPackage = new TestPackage(openFileDialog1.FileName);
var directoryName = Path.GetDirectoryName(openFileDialog1.FileName);
testPackage.BasePath = directoryName;
var suite = builder.Build(testPackage);
TestResult result = suite.Run(new NullListener(), TestFilter.Empty);
The problem is that I keep getting an exception thrown by builder.Build stating that the assembly was not found.
What am I missing?
Is there some other way to run the test from the code (without using Process.Start)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在开头添加以下行,设置 NUnit 框架并可能对您有所帮助:
以编程方式执行 NUnit 测试的另一种“更简单”方法是:
您需要引用以下程序集:
nunit.core.dll
nunit.core.interfaces.dll
当然,
nunit.framework.dll
必须位于测试程序集所在的文件夹中;)Adding the following line at the beginning, sets up the NUnit framework and might help you:
Another "easier" way to execute NUnit tests programmatically would be:
You need to reference the following assemblies:
nunit.core.dll
nunit.core.interfaces.dll
And of course, the
nunit.framework.dll
must be in the folder with your test assembly ;)