简体   繁体   English

NUnit TestFixture与TestCases

[英]NUnit TestFixture with TestCases

Does NUnit provide functionality to have TestCase attributes associated with a TestFixture ? NUnit是否提供使TestCase属性与TestFixture关联的功能? I'd like to run the same set of tests on different implementations of the same interface. 我想在同一接口的不同实现上运行同一组测试。 The concrete implementation would then be chosen in the SetUp method, and each test should be run with every implementation. 然后,将在SetUp方法中选择具体的实现,并且每个测试都应与每个实现一起运行。

I don't see any possibility for this. 我认为这没有任何可能性。 But nice idea anyway. 但是还是个好主意。

If you are not keen about the TestCase atribute you could use the TestCaseSource attribute with an abstract base class. 如果你并不热衷对TestCase属性约你可以使用TestCaseSource属性与抽象基类。

public abstract class A
{
    public class TestCases : List<TestCaseData>
    {
        public TestCases()
        {
            Add(new TestCaseData(1));
            Add(new TestCaseData(2));
        }
    }

    public abstract void Test(int i);
}

[TestFixture]
public class B : A
{
    [Test]
    [TestCaseSource(typeof(TestCases))]
    public override void Test(int i)
    {
        Assert.That(i, Is.GreaterThan(0));
    }
}

[TestFixture]
public class C : A
{
    [Test]
    [TestCaseSource(typeof(TestCases))]
    public override void Test(int i)
    {
        Assert.That(i, Is.LessThan(10));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM