0

I am making a unittest using the Nunit framework, and I am using the Combinatorial attribute, allowing me to provide argument data. I want to provide an int array that is within a range of 1-10 as argument data. The test is written as follows:

[TestFixture]
public class TestClass
{
    [Test]
    [Combinatorial]
    public void Test1(
        [Values(Enumerable.Range(1,10).ToArray())] int x)
    {
        Console.WriteLine(x);
    }
}

However, the Values attribute gives me the following error:

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

How do I create this constant int array, without having to type out all the individual numbers?

suitendaal
  • 149
  • 9
  • 2
    You can't. That's not how constants work. You probably want [`[TestCaseSource]`](https://docs.nunit.org/articles/nunit/writing-tests/attributes/testcasesource.html). – ProgrammingLlama Jun 01 '22 at 10:12
  • 1
    Thanks! Since I wanted to use multiple values, using the `Combinatorial` attribute, I solved it with [`[ValueSource]`](https://docs.nunit.org/articles/nunit/writing-tests/attributes/valuesource.html): `[ValueSource("array")] int x`, with `public static int[] array = Enumerable.Range(1,10).ToArray();` – suitendaal Jun 01 '22 at 11:33

0 Answers0