ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: NUnit. Implicitly unspecified null values.

Last modified: 11 February 2024

This inspection reports implicit values passed to NUnit tests annotated with the [Sequential] attribute.

When you use the [Sequential] attribute on a test where multiple parameters are annotated with the [Values] attribute, the number of generated test cases will correspond to the [Values] attribute with the maximum number of arguments. For attributes with fewer arguments, NUnit will implicitly use null for reference types or the default values for value types.

For example, for the following test

NUnit will generate 3 test cases because the first [Values] attribute is used with 3 arguments, but in the third case it will use null because the second attribute is used with only 2 arguments:

Although this is allowed by the NUnit specification, implicit values may lead to unexpected test results. To avoid this, it is recommended that all [Values] attributes in the test have the same number of arguments.