Search code examples
unit-testing

How can I run tests on all combinations?


I'm using xUnit.net as my testing framework, but I suppose this question applies to other frameworks. My method below takes two booleans. How can I test all combinations without having to write out each combination?

    [Theory,
    InlineData(false, false),
    InlineData(true, false),
    InlineData(false, true),
    InlineData(true, true)]
    public void Foo(bool A, bool B )

Is there a way to do something like:

    [Theory,
    SomeAttribute( for(int i=0; i<5; i++), for(int y=0; y<5; y++)),
    public void Foo(int A, int B )

that would run this test 5x5=25 times?


Solution

  •  public static IEnumerable<object[]> FooData
        {
            get
            {
                for (int a = 0; a < 2; a++)
                {
                    for (int b = 0; b < 2; b++)
                    {
                       yield return new object[] {a > 0, b > 0};
                    }   
                }
            }
        }
    
        [Theory]
        [PropertyData("FooData")]
        public void Foo(bool A, bool B)