Search Results for

    Show / Hide Table of Contents

    NUnit1003

    The TestCaseAttribute provided too few arguments

    Topic Value
    Id NUnit1003
    Severity Error
    Enabled True
    Category Structure
    Code TestCaseUsageAnalyzer

    Description

    The number of arguments provided by a TestCaseAttribute must match the number of parameters of the method.

    Motivation

    To prevent tests that will fail at runtime due to improper construction.

    How to fix violations

    Example Violation

    [TestCase("1")]
    public void NUnit1003SampleTest(string parameter1, string parameter2)
    {
        Assert.That(parameter1, Is.EqualTo("1"));
        Assert.That(parameter2, Is.EqualTo("2"));
    }
    

    Explanation

    In the sample above, the test expects two parameters ((string parameter1, string parameter2)), but only one argument is supplied by the test case (TestCase("1")).

    Fix

    Either add the additional argument:

    [TestCase("1", "2")]
    public void NUnit1003SampleTest(string parameter1, string parameter2)
    {
        Assert.That(parameter1, Is.EqualTo("1"));
        Assert.That(parameter2, Is.EqualTo("2"));
    }
    

    Or remove the use of that parameter:

    [TestCase("1")]
    public void NUnit1003SampleTest(string parameter1)
    {
        Assert.That(parameter1, Is.EqualTo("1"));
    }
    

    Configure severity

    Via ruleset file

    Configure the severity per project, for more info see MSDN.

    Via .editorconfig file

    # NUnit1003: The TestCaseAttribute provided too few arguments
    dotnet_diagnostic.NUnit1003.severity = chosenSeverity
    

    where chosenSeverity can be one of none, silent, suggestion, warning, or error.

    Via #pragma directive

    #pragma warning disable NUnit1003 // The TestCaseAttribute provided too few arguments
    Code violating the rule here
    #pragma warning restore NUnit1003 // The TestCaseAttribute provided too few arguments
    

    Or put this at the top of the file to disable all instances.

    #pragma warning disable NUnit1003 // The TestCaseAttribute provided too few arguments
    

    Via attribute [SuppressMessage]

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
        "NUnit1003:The TestCaseAttribute provided too few arguments",
        Justification = "Reason...")]
    
    • 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