Overview of implemented NUnit diagnostics and code fixes
In the tables below we use the following symbols:
- 🔍 - whether the diagnostic is enabled by default or not
- 📝 - the severity of the diagnostic
- 💡 - whether the diagnostic has an associated code fix or not
The severity of a diagnostic can the one of the following (in increasing severity):
- 💭 - indicates a severity of Hidden
- ℹ️ - indicates a severity of Info
- ⚠️ - indicates a severity of Warning
- ❗ - indicates a severity of Error
Structure Rules (NUnit1001 - )
Rules which enforce structural requirements on the test code.
Id | Title | 🔍 | 📝 | 💡 |
---|---|---|---|---|
NUnit1001 | The individual arguments provided by a TestCaseAttribute must match the type of the corresponding parameter of the method | ✅ | ❗ | ❌ |
NUnit1002 | The TestCaseSource should use nameof operator to specify target | ✅ | ⚠️ | ✅ |
NUnit1003 | The TestCaseAttribute provided too few arguments | ✅ | ❗ | ❌ |
NUnit1004 | The TestCaseAttribute provided too many arguments | ✅ | ❗ | ❌ |
NUnit1005 | The type of the value specified via ExpectedResult must match the return type of the method | ✅ | ❗ | ❌ |
NUnit1006 | ExpectedResult must not be specified when the method returns void | ✅ | ❗ | ❌ |
NUnit1007 | The method has non-void return type, but no result is expected in ExpectedResult | ✅ | ❗ | ❌ |
NUnit1008 | Specifying ParallelScope.Self on assembly level has no effect | ✅ | ⚠️ | ❌ |
NUnit1009 | One may not specify ParallelScope.Children on a non-parameterized test method | ✅ | ❗ | ❌ |
NUnit1010 | One may not specify ParallelScope.Fixtures on a test method | ✅ | ❗ | ❌ |
NUnit1011 | The TestCaseSource argument does not specify an existing member | ✅ | ❗ | ❌ |
NUnit1012 | The async test method must have a non-void return type | ✅ | ❗ | ❌ |
NUnit1013 | The async test method must have a non-generic Task return type when no result is expected | ✅ | ❗ | ❌ |
NUnit1014 | The async test method must have a Task<T> return type when a result is expected | ✅ | ❗ | ❌ |
NUnit1015 | The source type does not implement I(Async)Enumerable | ✅ | ❗ | ❌ |
NUnit1016 | The source type does not have a default constructor | ✅ | ❗ | ❌ |
NUnit1017 | The specified source is not static | ✅ | ❗ | ❌ |
NUnit1018 | The number of parameters provided by the TestCaseSource does not match the number of parameters in the target method | ✅ | ❗ | ❌ |
NUnit1019 | The source specified by the TestCaseSource does not return an I(Async)Enumerable or a type that implements I(Async)Enumerable | ✅ | ❗ | ❌ |
NUnit1020 | The TestCaseSource provides parameters to a source - field or property - that expects no parameters | ✅ | ❗ | ❌ |
NUnit1021 | The ValueSource should use nameof operator to specify target | ✅ | ⚠️ | ✅ |
NUnit1022 | The specified source is not static | ✅ | ❗ | ❌ |
NUnit1023 | The target method expects parameters which cannot be supplied by the ValueSource | ✅ | ❗ | ❌ |
NUnit1024 | The source specified by the ValueSource does not return an I(Async)Enumerable or a type that implements I(Async)Enumerable | ✅ | ❗ | ❌ |
NUnit1025 | The ValueSource argument does not specify an existing member | ✅ | ❗ | ❌ |
NUnit1026 | The test or setup/teardown method is not public | ✅ | ❗ | ✅ |
NUnit1027 | The test method has parameters, but no arguments are supplied by attributes | ✅ | ❗ | ❌ |
NUnit1028 | The non-test method is public | ✅ | ℹ️ | ✅ |
NUnit1029 | The number of parameters provided by the TestCaseSource does not match the number of parameters in the Test method | ✅ | ❗ | ❌ |
NUnit1030 | The type of parameter provided by the TestCaseSource does not match the type of the parameter in the Test method | ✅ | ❗ | ❌ |
NUnit1031 | The individual arguments provided by a ValuesAttribute must match the type of the corresponding parameter of the method | ✅ | ❗ | ❌ |
NUnit1032 | An IDisposable field/property should be Disposed in a TearDown method | ✅ | ❗ | ❌ |
NUnit1033 | The Write methods on TestContext will be marked as Obsolete and eventually removed | ✅ | ⚠️ | ✅ |
Assertion Rules (NUnit2001 - )
Rules which improve assertions in the test code.
Id | Title | 🔍 | 📝 | 💡 |
---|---|---|---|---|
NUnit2001 | Consider using Assert.That(expr, Is.False) instead of ClassicAssert.False(expr) | ✅ | ℹ️ | ✅ |
NUnit2002 | Consider using Assert.That(expr, Is.False) instead of ClassicAssert.IsFalse(expr) | ✅ | ℹ️ | ✅ |
NUnit2003 | Consider using Assert.That(expr, Is.True) instead of ClassicAssert.IsTrue(expr) | ✅ | ℹ️ | ✅ |
NUnit2004 | Consider using Assert.That(expr, Is.True) instead of ClassicAssert.True(expr) | ✅ | ℹ️ | ✅ |
NUnit2005 | Consider using Assert.That(actual, Is.EqualTo(expected)) instead of ClassicAssert.AreEqual(expected, actual) | ✅ | ⚠️ | ✅ |
NUnit2006 | Consider using Assert.That(actual, Is.Not.EqualTo(expected)) instead of ClassicAssert.AreNotEqual(expected, actual) | ✅ | ⚠️ | ✅ |
NUnit2007 | The actual value should not be a constant | ✅ | ⚠️ | ✅ |
NUnit2008 | Incorrect IgnoreCase usage | ✅ | ⚠️ | ❌ |
NUnit2009 | The same value has been provided as both the actual and the expected argument | ✅ | ⚠️ | ❌ |
NUnit2010 | Use EqualConstraint for better assertion messages in case of failure | ✅ | ℹ️ | ✅ |
NUnit2011 | Use ContainsConstraint for better assertion messages in case of failure | ✅ | ℹ️ | ✅ |
NUnit2012 | Use StartsWithConstraint for better assertion messages in case of failure | ✅ | ℹ️ | ✅ |
NUnit2013 | Use EndsWithConstraint for better assertion messages in case of failure | ✅ | ℹ️ | ✅ |
NUnit2014 | Use SomeItemsConstraint for better assertion messages in case of failure | ✅ | ℹ️ | ✅ |
NUnit2015 | Consider using Assert.That(actual, Is.SameAs(expected)) instead of ClassicAssert.AreSame(expected, actual) | ✅ | ⚠️ | ✅ |
NUnit2016 | Consider using Assert.That(expr, Is.Null) instead of ClassicAssert.Null(expr) | ✅ | ℹ️ | ✅ |
NUnit2017 | Consider using Assert.That(expr, Is.Null) instead of ClassicAssert.IsNull(expr) | ✅ | ℹ️ | ✅ |
NUnit2018 | Consider using Assert.That(expr, Is.Not.Null) instead of ClassicAssert.NotNull(expr) | ✅ | ℹ️ | ✅ |
NUnit2019 | Consider using Assert.That(expr, Is.Not.Null) instead of ClassicAssert.IsNotNull(expr) | ✅ | ℹ️ | ✅ |
NUnit2020 | Incompatible types for SameAs constraint | ✅ | ❗ | ❌ |
NUnit2021 | Incompatible types for EqualTo constraint | ✅ | ❗ | ❌ |
NUnit2022 | Missing property required for constraint | ✅ | ❗ | ✅ |
NUnit2023 | Invalid NullConstraint usage | ✅ | ❗ | ❌ |
NUnit2024 | Wrong actual type used with String Constraint | ✅ | ❗ | ❌ |
NUnit2025 | Wrong actual type used with ContainsConstraint | ❌ | 💭 | ❌ |
NUnit2026 | Wrong actual type used with the SomeItemsConstraint with EqualConstraint | ✅ | ❗ | ❌ |
NUnit2027 | Consider using Assert.That(actual, Is.GreaterThan(expected)) instead of ClassicAssert.Greater(actual, expected) | ✅ | ℹ️ | ✅ |
NUnit2028 | Consider using Assert.That(actual, Is.GreaterThanOrEqualTo(expected)) instead of ClassicAssert.GreaterOrEqual(actual, expected) | ✅ | ℹ️ | ✅ |
NUnit2029 | Consider using Assert.That(actual, Is.LessThan(expected)) instead of ClassicAssert.Less(actual, expected) | ✅ | ℹ️ | ✅ |
NUnit2030 | Consider using Assert.That(actual, Is.LessThanOrEqualTo(expected)) instead of ClassicAssert.LessOrEqual(actual, expected) | ✅ | ℹ️ | ✅ |
NUnit2031 | Consider using Assert.That(actual, Is.Not.SameAs(expected)) instead of ClassicAssert.AreNotSame(expected, actual) | ✅ | ⚠️ | ✅ |
NUnit2032 | Consider using Assert.That(expr, Is.Zero) instead of ClassicAssert.Zero(expr) | ✅ | ℹ️ | ✅ |
NUnit2033 | Consider using Assert.That(expr, Is.Not.Zero) instead of ClassicAssert.NotZero(expr) | ✅ | ℹ️ | ✅ |
NUnit2034 | Consider using Assert.That(expr, Is.NaN) instead of ClassicAssert.IsNaN(expr) | ✅ | ℹ️ | ✅ |
NUnit2035 | Consider using Assert.That(collection, Is.Empty) instead of ClassicAssert.IsEmpty(collection) | ✅ | ℹ️ | ✅ |
NUnit2036 | Consider using Assert.That(collection, Is.Not.Empty) instead of ClassicAssert.IsNotEmpty(collection) | ✅ | ℹ️ | ✅ |
NUnit2037 | Consider using Assert.That(collection, Does.Contain(instance)) instead of ClassicAssert.Contains(instance, collection) | ✅ | ℹ️ | ✅ |
NUnit2038 | Consider using Assert.That(actual, Is.InstanceOf(expected)) instead of ClassicAssert.IsInstanceOf(expected, actual) | ✅ | ℹ️ | ✅ |
NUnit2039 | Consider using Assert.That(actual, Is.Not.InstanceOf(expected)) instead of ClassicAssert.IsNotInstanceOf(expected, actual) | ✅ | ℹ️ | ✅ |
NUnit2040 | Non-reference types for SameAs constraint | ✅ | ❗ | ✅ |
NUnit2041 | Incompatible types for comparison constraint | ✅ | ❗ | ❌ |
NUnit2042 | Comparison constraint on object | ✅ | ℹ️ | ❌ |
NUnit2043 | Use ComparisonConstraint for better assertion messages in case of failure | ✅ | ℹ️ | ✅ |
NUnit2044 | Non-delegate actual parameter | ✅ | ❗ | ✅ |
NUnit2045 | Use Assert.Multiple | ✅ | ℹ️ | ✅ |
NUnit2046 | Use CollectionConstraint for better assertion messages in case of failure | ✅ | ℹ️ | ✅ |
NUnit2047 | Incompatible types for Within constraint | ✅ | ⚠️ | ✅ |
NUnit2048 | Consider using Assert.That(...) instead of StringAssert(...) | ✅ | ⚠️ | ✅ |
NUnit2049 | Consider using Assert.That(...) instead of CollectionAssert(...) | ✅ | ⚠️ | ✅ |
NUnit2050 | NUnit 4 no longer supports string.Format specification | ✅ | ❗ | ✅ |
NUnit2051 | Consider using Assert.That(expr, Is.Positive) instead of ClassicAssert.Positive(expr) | ✅ | ℹ️ | ✅ |
NUnit2052 | Consider using Assert.That(expr, Is.Negative) instead of ClassicAssert.Negative(expr) | ✅ | ℹ️ | ✅ |
NUnit2053 | Consider using Assert.That(actual, Is.AssignableFrom(expected)) instead of ClassicAssert.IsAssignableFrom(expected, actual) | ✅ | ℹ️ | ✅ |
NUnit2054 | Consider using Assert.That(actual, Is.Not.AssignableFrom(expected)) instead of ClassicAssert.IsNotAssignableFrom(expected, actual) | ✅ | ℹ️ | ✅ |
Suppressor Rules (NUnit3001 - )
Rules which suppress compiler errors based on context. Note that these rules are only available in the .NET Standard 2.0 builds (version 3.0.0 and above) which require Visual Studio 2019 (version 16.3) or newer.
Id | Title | 🔍 | 📝 | 💡 |
---|---|---|---|---|
NUnit3001 | Expression was checked in an ClassicAssert.NotNull, ClassicAssert.IsNotNull or Assert.That call | ✅ | ℹ️ | ❌ |
NUnit3002 | Field/Property is initialized in SetUp or OneTimeSetUp method | ✅ | ℹ️ | ❌ |
NUnit3003 | Class is an NUnit TestFixture and is instantiated using reflection | ✅ | ℹ️ | ❌ |
NUnit3004 | Field should be Disposed in TearDown or OneTimeTearDown method | ✅ | ℹ️ | ❌ |
Style Rules (NUnit4001 - )
Rules which help you write concise and readable NUnit test code.
Id | Title | 🔍 | 📝 | 💡 |
---|---|---|---|---|
NUnit4001 | Simplify the Values attribute | ✅ | ℹ️ | ❌ |