gpt4 book ai didi

c# - 如何为 N 单元测试使用多个 TestCaseSource 属性

转载 作者:太空狗 更新时间:2023-10-29 17:44:54 26 4
gpt4 key购买 nike

如何使用多个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com