【发布时间】:2015-07-08 00:00:13
【问题描述】:
我需要在我的 NUnit c# 应用程序中订购测试装置。我有一个关于如何从this page 运行有序测试方法的示例,并且我尝试使用示例应用程序中提供的相同方法为测试夹具实现相同的逻辑。在我们的应用程序中 每个类都有一个测试夹具,每个测试夹具都有一个测试方法。我们最近的尝试是使用继承自一个名为 OrderedTestFixture 的类的父测试夹具(与示例中相同),它具有以下方法:
public IEnumerable<NUnit.Framework.TestCaseData> TestSource
{
get
{
var assembly = Assembly.GetExecutingAssembly();
foreach (var order in methods.Keys.OrderBy(x => x))
{
foreach (var methodInfo in methods[order])
{
MethodInfo info = methodInfo;
yield return new NUnit.Framework.TestCaseData(
new TestStructure
{
Test = () =>
{
object classInstance = Activator.CreateInstance(info.DeclaringType, null);
info.Invoke(classInstance, null);
}
}).SetName(methodInfo.Name);
}
}
}
}
这个方法应该按顺序返回将要执行的测试方法。但是,即使它按顺序返回测试方法,也无法按顺序执行它们。
我使用的逻辑与 App 示例中的完全相同。一个从 Attribute 继承的 orderedTestAttrribute 类,它将被放置在每个测试方法中,如下所示:
[Test]
[OrderedTest(1)]
[BeforeAfterTest]
public void TestMethod() { }
有没有人知道如何在不改变我当前的实现的情况下完成这项工作,即分别拥有一个 testFixture 和一个测试类?
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
你能告诉我们返回创建
methods的代码吗? -
我展示的是返回“方法”的那个,你到底需要我展示什么?
-
下面我的回答解决了你的问题吗?
-
我们在框架中检查了它是如何获取固定装置的。为了节省时间,我们只是简单地添加了一个数字前缀让它们按顺序执行。
标签: c# nunit automated-tests integration-testing ordered-test