NUnit TestCase - Arrays as attribute argument is not CLS-compliant

896 Views Asked by At

I have a testcase attribute with four arguments:

[TestCase("2007", "52", "saturday", "2007/12/29")]

The compiler says:

Arrays as attribute arguments is not CLS-compliant.

If I remove one argument, its works perfect. So, it's not clear to me why testcases with four attributes are not CLS-compliant. I'm using NUnit 3.5.

1

There are 1 best solutions below

0
Chris On BEST ANSWER

This is because, under the hood, NUnit's TestCaseAttribute actually has 4 different constructors.

    public TestCaseAttribute(object arg)
    {
    }

    public TestCaseAttribute(object arg1, object arg2)
    {
    }

    public TestCaseAttribute(object arg1, object arg2, object arg3)
    {
    }

    //Not CLS compliant
    public TestCaseAttribute(params object[] arguments)
    {
    }

As you can see - for 1-3 parameters, there are specific constructors, whereas for >3, it defaults to the non-CLS compliant version, which uses an object[] instead. And as the compiler says, arrays as attribute arguments are not CLS compliant.

If you need to be CLS compliant, you could get around this using a TestCaseSourceAttribute instead.