Nunit 你能把iterable传递给像pytest这样的Nuint测试吗?

Nunit 你能把iterable传递给像pytest这样的Nuint测试吗?,nunit,Nunit,使用Pytest,您可以将iterable传递给一个测试方法,它将运行多个测试: the_data = [1,2,3,4,5,a,6,7,8] @pytest.mark.parameterize('arg', the_data) def test_data(arg): assert arg.isnumeric() 你能用Nunit(使用c#)做到这一点吗?是的,你会像下面那样使用[TestCaseSource] [TestCaseSource(nameof(TheData))] pu

使用Pytest,您可以将iterable传递给一个测试方法,它将运行多个测试:

the_data = [1,2,3,4,5,a,6,7,8]

@pytest.mark.parameterize('arg', the_data)
def test_data(arg):
    assert arg.isnumeric()

你能用Nunit(使用c#)做到这一点吗?

是的,你会像下面那样使用
[TestCaseSource]

[TestCaseSource(nameof(TheData))]
public void TestData(object i)
{
    Assert.That(i is int);
}

public static IEnumerable TheData => new object[] { 1, 2, 3, 4, 5, 'a', 6, 7, 8 };
请注意,测试数据必须是静态的。上述结果将在VisualStudio中使用NUnit测试适配器进行以下测试


在迭代之间,它没有运行我的[设置]。