我想测试一个具有高圈复杂度的方法(叹息),我想在测试类中有一个类,这样一个方法测试类就会作为树中的一个节点出现。 Nunit 是否可行?如何实现?
MyEntityTests
|
L_ MyComplexMethodTests
L when_some_condition_than
L when_some_other_condition_than
[TestFixture]
public class MyEntityTests
{
[TestFixture]
public class MyComplexMethodTests
{
[Test]
public void when_some_condition_than() {}
etc.....
}
}
最佳答案
您可以使用嵌套类来实现,这与您问题中的示例代码非常相似。
与您的代码的唯一区别是外部类不需要 [TestFixture]
属性,如果它仅用于结构并且本身没有测试的话。
您还可以让所有内部类共享一个Setup
方法,方法是将它放入外部类并让内部类继承外部类:
using NUnit.Framework;
namespace My.Namespace
{
public class MyEntityTests
{
[SetUp]
public void Setup()
{
}
[TestFixture]
public class MyComplexMethodTests : MyEntityTests
{
[Test]
public void when_some_condition_than()
{
}
[Test]
public void when_some_other_condition_then()
{
}
}
}
}
在 NUnit GUI 中,这个测试类将如下所示:
关于c# - Nunit:是否可以让测试出现嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3015145/