如何使用多个 TestCaseSource 属性为 N-Unit 2.62 中的测试提供测试数据?
我目前正在做以下事情:
[Test, Combinatorial, TestCaseSource(typeof(FooFactory), "GetFoo"), TestCaseSource(typeof(BarFactory), "GetBar")]
FooBar(Foo x, Bar y)
{
//Some test runs here.
}
我的测试用例数据源如下所示:
internal sealed class FooFactory
{
public IEnumerable<Foo> GetFoo()
{
//Gets some foos.
}
}
internal sealed class BarFactory
{
public IEnumerable<Bar> GetBar()
{
//Gets some bars.
}
}
不幸的是,N-Unit 甚至不会启动测试,因为它说我提供了错误数量的参数。我知道您可以指定一个 TestCaseObject 作为返回类型并传入一个对象数组,但我认为这种方法是可行的。
你能帮我解决这个问题吗?
最佳答案
在这种情况下使用的适当属性是 ValueSource
。本质上,您是在为每个参数指定一个数据源,就像这样。
public void TestQuoteSubmission(
[ValueSource(typeof(FooFactory), "GetFoo")] Foo x,
[ValueSource(typeof(BarFactory), "GetBar")] Bar y)
{
// Your test here.
}
这将启用我使用 TestCaseSource
属性寻找的功能类型。
关于c# - 如何为 N 单元测试使用多个 TestCaseSource 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16346903/