Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit Sequential/Combinatorial Question

Tags:

c#

nunit

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

like image 545
Yends Avatar asked Dec 22 '22 09:12

Yends


1 Answers

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:

[Test, Sequential]
public void TestDivisionBy2(
    [Values(10, 25, 40)] int input,
    [Values(5, 12, 20)] int expectedOutput)
{
    Assert.AreEqual(expectedOutput, input / 2);
}
like image 198
Jon Skeet Avatar answered Dec 24 '22 00:12

Jon Skeet