gpt4 book ai didi

C# NUnit TestCaseSource 传递参数

转载 作者:可可西里 更新时间:2023-11-01 08:33:54 24 4
gpt4 key购买 nike

我有以下生成一组测试用例的方法!

public IEnumerable<ResultsOfCallMyMethod> PrepareTestCases(param1)
{
foreach (string entry in entries)
{
yield return callMyMethod(param1);
}
}

如何将字符串类型的参数作为参数传递给我的 PrepareTestCases() 方法?

有没有办法做到以下几点:

[Test, Category("Integration"), TestCaseSource("PrepareTestCases", param1)]
public void TestRun(ResultsOfCallMyMethod testData)
{
// do something!
}

最佳答案

我在即将发布的最新版nunit(3.2)中对此进行了修改。

https://github.com/nunit/nunit/blob/4f54fd7e86f659682e7a538dfe5abee0c33aa8b4/CHANGES.txt

  • TestCaseSourceAttribute now optionally takes an array of parameters that can be passed to the source method

现在可以做这样的事情了

[Test, Category("Integration"), TestCaseSource(typeof(MyDataSources),"PrepareTestCases", new object[] {param1})]
public void TestRun(ResultsOfCallMyMethod testData)
{
// do something!
}

private class MyDataSources
{
public IEnumerable<ResultsOfCallMyMethod> PrepareTestCases(param1)
{
foreach (string entry in entries)
{
yield return callMyMethod(param1);
}
}
}

关于C# NUnit TestCaseSource 传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28603507/

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