Search code examples
c#nunitnunit-3.0

Is there a way to use "params" in NUnit test method with TestCaseSource


NUnit 3.13.3

I Have a following test method:

[TestCaseSource(nameof(_myTestMethodCases))]
public void MyTestMethod(string text, int number, params Cat[] cats)
{
    foreach(var cat in cats)
    {
       // Do stuff
    }

    // Do other stuff

    // Assert
}

And a following field representing test cases:

private static object[] _myTestMethodCases
{
    new object[] { "testA", 10, new Cat("Lua"), new Cat("Julia") }
    new object[] { "testB", 20 }
    new object[] { "testC", 20, new Cat("Ruby") }
}

But when i try to run test i get an exception: Not enough arguments provided, provide at least 3 arguments. in all cases.

How can I make it work, except creating a method as TestCaseSource?


Solution

  • This is a known bug in TestCaseSource, at least in some versions of NUnit. Just add new Cat[0] as the third argument to TestB.