简体   繁体   中英

NUnit and TestCaseAttribute, cross-join of parameters possible?

I have a unit-test that tests a variety of cases, like this:

public void Test1(Int32 a, Int32 b, Int32 c)

Let's say I want to create test-code without a loop, so I want to use TestCase to specify parameters like this:

[TestCase(1, 1, 1)]
public void Test1(Int32 a, Int32 b, Int32 c)

Is it possible for me with this attribute to say this:

  • For the first parameter, here's a set of values
  • For the second parameter, here's a set of values
  • For the third parameter, here's a set of values
  • Now, test all combinations of the above

Ie. something like this:

[TestCase(new[] { 1, 2, 3, 4 }, new[] { 1, 2, 3, 4 }, new[] { 1, 2, 3, 4 })]
public void Test1(Int32 a, Int32 b, Int32 c)

Doesn't seem like it, but perhaps I'm overlooking something?

NUnit provides the Values attribute which can be used together with Combinatorial attribute to achieve this:

[Test, Combinatorial]
public void Test1( 
    [Values(1,2,3,4)] Int32 a, 
    [Values(1,2,3,4)] Int32 b, 
    [Values(1,2,3,4)] Int32 c
)
{
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM