NUnit 顺序/组合问题
我正在编写一些单元测试并想要使用 Sequential 标签,我已经找到了声明此类测试的语法。
[Test, Sequential]
public void TestCalculations(
[Values(10000, 15000, 20000, 25000, 50000)] int salary)
{
}
在进行诸如具有多个输入的顺序/组合之类的测试时,如何处理断言?
最好的祝愿
I am writing some unit tests and want to make use of Sequential tag, I have found the syntax for delclaring such a test.
[Test, Sequential]
public void TestCalculations(
[Values(10000, 15000, 20000, 25000, 50000)] int salary)
{
}
How are assertions handled when doing tests like sequential/combinatorial with multiple inputs?
Best Wishes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己没有使用过这些属性,但我希望编写实际的测试方法主体,就像为单个值编写它一样。基本上,您一次只会看到一个值,因此只需编写代码来测试该值即可。
鉴于文档,我不认为
顺序
对于您的示例确实有意义,因为您只有一个参数。当您有多个参数时,这是有意义的,并且基本上表示一个参数的第一个值应与另一个参数的第一个值配对,然后是每个参数的第二个值,等等,而不是每个参数可能正在执行的对。您可以使用它来提供输入和预期输出,例如:I haven't used these attributes myself, but I'd expect to write the actual test method body exactly as if you were writing it for a single value. Basically you'll only be presented with one value at a time, so just write the code to test that value.
Given the documentation, I don't think
Sequential
really makes sense for your example, because you've only got one parameter. It makes sense when you've got multiple parameters, and basically says that the first value for one parameter should be paired with the first value for another parameter, then the second value for each etc, rather than each possible pair being executed. You might use that to give input and expected output, for example:在某些情况下 TestCase 属性可能很有用,它提供内置功能
Result
:如果您不期望任何特定的结果值,而只是想确保测试在不同的输入值下正常工作 - 您也可以这样做:
In some cases TestCase attribute could be useful, it provides built in feature
Result
:If you do not expect any specific result value and just want to ensure that test works fine with different input values - you can do it as well: