在顺序运行TestFixtures与NUnit的 [英] Run TestFixtures in Order with NUnit

查看:309
本文介绍了在顺序运行TestFixtures与NUnit的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有序的测试设备在我的NUnit的C#应用​​程序。我对如何运行此页和我试图实现相同的逻辑测试夹具与示例应用程序提供的相同的方法。在我们的应用
测试夹具被分离为每个类和每个测试夹具具有一个测试方法。我们最新的尝试是使用父测试夹具从一个叫做类继承:OrderedTestFixture(一样的例子),它具有以下方法:

I need to have ordered test fixtures in my NUnit c# Application. I have an example on how to run ordered test methods from this page, and I've tried to implement the same logic for test fixtures with the same methods provided in the example application. In our application a test fixture is separated for each class and each test fixture has one test method. Our latest attempt was to use a Parent Test Fixture which inherits from a class called: OrderedTestFixture (the same as in the example), which has the following method:

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

此方法应该返回,为了,测试方法,将执行。但是,即使它返回为了测试方法,它失败以执行它们。

This method is supposed to return, in order, the test methods that will execute. However, even if it returns the test methods in order, it fails to execute them in order.

我使用的是完全相同的逻辑,在App的例子。一个orderedTestAttrribute类,从属性将被放置在每个测试方法像这样继承了:

I'm using the same exact logic as in the App example. An orderedTestAttrribute class that inherits from Attribute that will be placed in every test method like this:

[Test]
[OrderedTest(1)]
[BeforeAfterTest]
public void TestMethod() { }

是否有任何人有任何想法,我怎样才能使这项工作不改变有一个用的TestFixture我目前执行一个测试类分开?

Does anyone out there have any idea how can I make this work without changing my current implementation of having one testFixture with one test class separately?

推荐答案

好吧,所以如果我理解正确的话,你要跨多个TestFixtures订购测试。因此,在这种情况下,你不希望使用OrderedTestFixture,因为这是专为无法跨多个灯具运行测试。如果你看一下从刚才的问题我的GitHub库,你要遵循例2 code。请注意,在这种情况下,你应该只使用OrderedTest属性 - 使用测试将引发整个事情了,因为那将只是通过随机安排的NUnit而不是通过使用TestCaseData被订购。回头参考我的博客文章了解更多详细信息。

Ok, so if I understand you correctly, you want to order test across multiple TestFixtures. So in this case, you don't want to use the OrderedTestFixture because that was specifically created to NOT run test across multiple fixtures. If you look at my GitHub repo from the earlier question, you'll want to follow the Example 2 code. Note that in this case you should only use the OrderedTest attribute - using Test will throw the whole thing off because then it will just be randomly scheduled by NUnit instead of being ordered through the use of TestCaseData. Refer back to my blog post for more details.

希望有所帮助。

这篇关于在顺序运行TestFixtures与NUnit的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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