Unit testing NUnit TestFixture和测试用例
NUnit是否提供与Unit testing NUnit TestFixture和测试用例,unit-testing,nunit,Unit Testing,Nunit,NUnit是否提供与TestFixture关联的TestCase属性的功能?我想在同一接口的不同实现上运行相同的测试集。然后在设置方法中选择具体的实现,每个测试都应该与每个实现一起运行。我看不出有任何可能性。不过这主意不错 如果您对TestCaseatribute不感兴趣,那么可以使用带有抽象基类的TestCaseSource属性 public abstract class A { public class TestCases : List<TestCaseData>
TestFixture
关联的TestCase
属性的功能?我想在同一接口的不同实现上运行相同的测试集。然后在设置方法中选择具体的实现,每个测试都应该与每个实现一起运行。我看不出有任何可能性。不过这主意不错
如果您对TestCase
atribute不感兴趣,那么可以使用带有抽象基类的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));
}
}
公共抽象类A
{
公共类测试用例:列表
{
公共测试用例()
{
添加(新的TestCaseData(1));
添加(新的TestCaseData(2));
}
}
公开摘要无效测试(int i);
}
[测试夹具]
B级:A级
{
[测试]
[TestCaseSource(typeof(TestCases))]
公共覆盖无效测试(int i)
{
断言(i,大于(0));
}
}
[测试夹具]
公共C类:A
{
[测试]
[TestCaseSource(typeof(TestCases))]
公共覆盖无效测试(int i)
{
断言(i,Is.LessThan(10));
}
}