[英]NUnit Sequential/Combinatorial Question
I am writing some unit tests and want to make use of Sequential tag, I have found the syntax for delclaring such a test. 我正在编写一些单元测试并希望使用Sequential标签,我已经找到了用于对这样的测试进行定界的语法。
[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 最好的祝愿
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. 鉴于文档 ,我不认为
Sequential
真的对你的例子有意义,因为你只有一个参数。 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:
您可以使用它来提供输入和预期输出,例如:
[Test, Sequential]
public void TestDivisionBy2(
[Values(10, 25, 40)] int input,
[Values(5, 12, 20)] int expectedOutput)
{
Assert.AreEqual(expectedOutput, input / 2);
}
In some cases TestCase attribute could be useful, it provides built in feature Result
: 在某些情况下, TestCase属性可能很有用,它提供内置功能
Result
:
[TestCase(12,3, Result=4)]
[TestCase(12,2, Result=6)]
[TestCase(12,4, Result=3)]
public int DivideTest(int n, int d)
{
return( n / d );
}
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: 如果您不希望任何特定的结果值,并且只是想确保测试在不同的输入值下正常工作 - 您也可以这样做:
[TestCase(120000, -1)]
[TestCase(Int32.MinValue, Int32.MaxValue)]
[TestCase(-1, 23333)]
public void ShouldHandleWrongRangeValues(int n, int d)
{
Assert.DoesNotThrow(() => { var someIntermediateValue = n * d; });
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.