Search Results for

    Show / Hide Table of Contents

    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

    1. When used on a generic method, ensure all combinations of generated arguments are valid.
    2. If multiple parameters share the same generic type (for example, T), some generated combinations may be invalid.
    3. Use Sequential or Pairwise when combinatorial generation produces too many or unsuitable combinations.

    See Also

    • Sequential Attribute
    • Pairwise Attribute
    • Values Attribute
    • Edit this page
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0