Search Results for

    Show / Hide Table of Contents

    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 ✅ â„šī¸ ❌
    • Edit this page
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0