【发布时间】:2019-08-18 04:48:39
【问题描述】:
有没有办法在 xUnit 中自动生成多个测试用例?还是我注定将每个可能的输入都指定为InlineData?
在下面的示例中,在 NCrunch 或 VS 测试运行程序中,它看起来像一个随机数被传递给测试。因此,每次运行测试时,它都有可能通过,尽管它应该会失败。
在 NUnit 中,Range 属性实际上根据https://github.com/nunit/docs/wiki/Range-Attribute 生成测试用例的多个排列
public bool RangeTest(int input)
{
if (input > 10)
{
return false;
}
return true;
}
[Theory]
[AutoMockData]
public void RangeTestCase([Range(0, 11)] int test)
{
var result = RangeTest(test);
Assert.True(result);
}
【问题讨论】:
标签: c# xunit xunit.net autofixture