我有以下方法可以生成一组测试用例!
public IEnumerable<ResultsOfCallMyMethod> PrepareTestCases(param1)
{
foreach (string entry in entries)
{
yield return callMyMethod(param1);
}
}
如何将字符串类型的 param 作为参数传递给我的PrepareTestCases()
method?
有没有办法执行以下操作:
[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 https://github.com/nunit/nunit/blob/4f54fd7e86f659682e7a538dfe5abee0c33aa8b4/CHANGES.txt
- TestCaseSourceAttribute 现在可以选择采用参数数组
可以传递给源方法
现在可以做这样的事情
[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);
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)