DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Run Multiple NUnit Test Cases

Define each input set as a separate NUnit test with repeated [TestCase] attributes, or move larger data sets into [TestCaseSource]. Learn how to run and filter the resulting cases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To test several inputs with one NUnit method, add a [TestCase] attribute for each input set; NUnit discovers each set as a separate test. To execute several discovered tests, run dotnet test, select them in Visual Studio Test Explorer, or filter by category with NUnit’s selection language.

Define several cases with repeated [TestCase] attributes

For a handful of fixed, readable examples, put one [TestCase(...)] above the test method for each argument set. Each attribute creates a separate invocation of that method.

using NUnit.Framework;

public class DivisionTests
{
    [TestCase(12, 3, 4)]
    [TestCase(12, 2, 6)]
    [TestCase(12, 4, 3)]
    public void Divide_ReturnsExpectedQuotient(int numerator, int denominator, int expected)
    {
        Assert.That(numerator / denominator, Is.EqualTo(expected));
    }
}

The method parameters correspond, in order, to the values in each attribute. The assertion runs independently for each set, so a failure identifies a particular case rather than stopping a loop inside one test. NUnit describes the behavior simply: multiple argument sets create multiple tests (Parameterized Tests).

Use [TestCaseSource] for larger or reusable data

When cases are lengthy, shared, or generated, place them in a separate source instead of crowding the method declaration. The source can be a field, property, or method that returns an enumerable of compatible arguments. Current NUnit documentation requires the source member to be static.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
using System.Collections.Generic;
using NUnit.Framework;

public class DivisionSourceTests
{
    private static IEnumerable<TestCaseData> DivisionCases()
    {
        yield return new TestCaseData(12, 3, 4);
        yield return new TestCaseData(12, 2, 6);
        yield return new TestCaseData(12, 4, 3);
    }

    [TestCaseSource(nameof(DivisionCases))]
    public void Divide_ReturnsExpectedQuotient(int numerator, int denominator, int expected)
    {
        Assert.That(numerator / denominator, Is.EqualTo(expected));
    }
}

nameof keeps the source reference refactor-safe. Ensure each yielded case supplies values assignable to the test method’s parameters. See NUnit’s TestCaseSource documentation for source forms and constraints.

Choose between the two attributes

Use Best fit Data location
[TestCase] A few stable, simple cases Inline above the method
[TestCaseSource] A larger, shared, or generated set A separate static field, property, or method

Run all tests or select multiple tests

Run the project from the command line

From the directory containing the test project, run:

dotnet test

This runs the project’s tests through the configured .NET test tooling. If you want a subset by category, pass NUnit’s selection expression after the -- separator:

dotnet test -- NUnit.Where="cat == Unit || cat == Integration"

The separator passes the argument to the test host, while NUnit.Where supplies NUnit’s own selection expression. Category names are case-sensitive. Mark tests with categories such as Unit or Integration using NUnit’s Category attribute. Check that your installed runner and adapter support the filter syntax you use; NUnit’s Test Selection Language documents supported expressions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale

Select tests in Visual Studio Test Explorer

  1. Build the solution so the NUnit adapter can discover tests.
  2. Open Test Explorer and wait for discovery to finish.
  3. Choose Run All to execute all discovered tests, or select several entries and run the selection from the context menu.

Parameterized cases appear as separate entries, so you can run one case or a selected group. See the adapter’s Usage documentation for its Visual Studio workflow.

Use the NUnit console runner when applicable

If you run the NUnit console runner against a test assembly, its selection language uses --where:

nunit3-console MyTests.dll --where "cat == Unit || cat == Integration"

This is the console runner’s syntax; do not assume it is interchangeable with another runner’s filtering options.

Discovery, case order, and independence

NUnit discovers parameterized invocations as separate tests, which makes them individually visible and selectable. Do not use repeated attribute order as a way to control execution order: discovery and execution order may differ. A single [TestCaseSource] preserves the order returned by that source, but combining multiple data-providing attributes can leave ordering undefined.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Keep cases independent so each can run alone or in a different order.
  • Do not make one case depend on data or side effects left by another.
  • If a real workflow requires sequencing, express that dependency explicitly rather than relying on discovery order.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot missing or unexpectedly selected cases

No parameterized cases appear

  • Build the test project and allow the adapter to discover tests; in Visual Studio, discovery follows a build.
  • Confirm the method has the NUnit parameterized-test attribute and that the project’s test tooling recognizes NUnit.

A case fails before the assertion

  • Compare the argument count and types with the test method’s parameters.
  • For [TestCaseSource], verify the source returns enumerable argument sets compatible with the method and that the source member is static.

The filter runs no tests

  • Check category spelling and capitalization; category names are case-sensitive.
  • Use the filter syntax for the runner in use: NUnit.Where after -- with dotnet test, or --where with the NUnit console runner.
  • Confirm that the categories are assigned to the tests and that the installed adapter/runner supports the requested selection behavior.

Tests behave differently between runs

Look for hidden ordering dependencies or shared mutable state. Repeated [TestCase] attributes do not establish a reliable execution sequence.

Version scope

The NUnit documentation introduction covers NUnit 3.0 and higher. Older framework or adapter versions may differ, so verify feature and filter support against the versions installed in your project (NUnit Documentation).

Or skip the browser setup

If the task is capturing website screenshots for test fixtures, ScreenshotNeo can return a screenshot or PDF from one GET request. For example, save a WebP capture of a test URL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify page verdict and billing status in headers. Its MCP server offers screenshot and PDF tools to AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Visit ScreenshotNeo for details, or sign up free.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.