C# an attribute argument must be a constant expression

cnunittestingvisual studiovisual studio 2012

Why does my String array below give me an Error, arent they all strings???
"An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type"

[Test]
[TestCase(new string[]{"01","02","03","04","05","06","07","08","09","10"},TestName="Checking10WOs")]
public void Test(String[] recordNumber)
{
     //something..
} 

Best Answer

This does not answer to the title of question, however it solves your specific problem.

You might want to use TestCaseSource, it allows you to pass multiple test case scenarios into the same testing mechanism, and you can use it as complex structures as you like.

    [Test]
    [TestCaseSource("TestCaseSourceData")]
    public void Test(String[] recordNumber, string testName)
    {
        //something..
    }

    public static IEnumerable<TestCaseData> TestCaseSourceData()
    {
        yield return new TestCaseData(new string[] {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10"}, "Checking10WOs");
    }

It will figure out that the first parameter is recordNumber and the second is testName

see the screenshot below.

enter image description here

Hope this saves you some time.