Sequential
SequentialAttribute tells NUnit to generate test cases by matching parameter values by index rather than creating additional combinations.
Usage
This is a parameterless attribute that can only be applied to test methods.
[Sequential]
Applies To
| Test Methods | Test Fixtures (Classes) | Assembly |
|---|---|---|
| ✅ | ❌ | ❌ |
Note
If parameter data is provided by multiple attributes, the order in which NUnit uses the data items is not guaranteed. However, it can be expected to remain constant for a given runtime and operating system. For best results with SequentialAttribute use only one data attribute on each parameter.
Example
The following test is executed three times.
[Test]
[Sequential]
public void MyTest(
[Values(1, 2, 3)] int x,
[Values("A", "B")] string s)
{
Assert.That(x, Is.GreaterThan(0));
Assert.That(s is null || s.Length > 0);
}
MyTest is called three times, as follows:
MyTest(1, "A")
MyTest(2, "B")
MyTest(3, null)
Notes
Sequentialpairs values from each parameter by position (index 0withindex 0, and so on).- If parameter data lengths differ, missing entries are filled using the default value for that parameter type.
- Prefer one data-providing attribute per parameter when using
Sequentialto avoid ordering ambiguities.