Combinatorial
CombinatorialAttribute is used on a test method to tell NUnit to generate test cases for all possible combinations of parameter values.
This is NUnit's default combining strategy, so using this attribute is optional unless you want to be explicit.
Usage
This is a parameterless attribute that can only be applied to test methods.
[Combinatorial]
Applies To
| Test Methods | Test Fixtures (Classes) | Assembly |
|---|---|---|
| ✅ | ❌ | ❌ |
Example
The following test is executed six times:
[Test]
[Combinatorial]
public void MyTest(
[Values(1, 2, 3)] int x,
[Values("A", "B")] string s)
{
Assert.That(x, Is.GreaterThan(0));
Assert.That(s, Is.Not.Null);
}
MyTest is called six times, as follows:
MyTest(1, "A")
MyTest(1, "B")
MyTest(2, "A")
MyTest(2, "B")
MyTest(3, "A")
MyTest(3, "B")
Notes
- When used on a generic method, ensure all combinations of generated arguments are valid.
- If multiple parameters share the same generic type (for example,
T), some generated combinations may be invalid. - Use
SequentialorPairwisewhen combinatorial generation produces too many or unsuitable combinations.