Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

nunit

/nunit

Pomaga pisać testy jednostkowe w NUnit dla C# i F#: asercje, fixture'y, testy parametryzowane oraz uruchamianie przez dotnet test.

Repozytorium
Agent-Skills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
01.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 01.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga pisać testy jednostkowe w NUnit dla C# i F#: asercje, fixture'y, testy parametryzowane oraz uruchamianie przez dotnet test.

Oryginalny opis (EN)

Expert NUnit testing assistance covering .NET assertions, test fixtures, and parameterized testing. Use when writing C# / F# unit tests, testing .NET solutions, or running `dotnet test`.

Jak działa

  1. When to Use
  2. Quick Start
  3. Core Concepts
  4. Common Patterns
  5. Best Practices
  6. Troubleshooting
  7. References
Sekcje z nagłówków SKILL.md, w oryginale · 159 linii, 536 słów
Podgląd SKILL.md
---
name: nunit
description: Expert NUnit testing assistance covering .NET assertions, test fixtures, and parameterized testing. Use when writing C# / F# unit tests, testing .NET solutions, or running `dotnet test`.
---

# NUnit

Ported from JUnit, NUnit is one of the oldest and most feature-rich frameworks for .NET. Ideally suited for complex test setups and legacy migrations.

## When to Use

- **C# and .NET Testing**: A mature, feature-rich testing framework widely used across enterprise .NET applications.
- **Parameterized & Combinatorial Testing**: Generating test matrices effortlessly with `[TestCase]` and `[Combinatorial]`.
- **Constraint-Based Assertions**: Writing expressive assertions using the `Assert.That()` syntax.
- **ASP.NET Core & Unity Game Testing**: Testing web APIs, microservices, and Unity game scripts.

## Quick Start

```csharp
using NUnit.Framework;

[TestFixture]
public class Tests
{
    [SetUp]
    public void Setup()
    {
    }

    [Test]
    public void Test1()
    {
        Assert.Pass();
    }

    [TestCase(1, 2, 3)]
    [TestCase(2, 2, 4)]
    public void TestAdd(int a, int b, int expected)
    {
       Assert.AreEqual(expected, a + b);
    }
}
```

## Core Concepts

### Constraint-Based Assertion Model

NUnit emphasizes fluent constraint assertions over legacy multiple-assert methods:

```csharp
using NUnit.Framework;

[TestFixture]
public class AccountTests
{
    [Test]
    public void TestDepositIncreasesBalance()
    {
        var account = new Account(100);
        account.Deposit(50);

        Assert.That(account.Balance, Is.EqualTo(150));
        Assert.That(account.Transactions, Has.Count.EqualTo(1));
        Assert.That(account.Owner, Does.StartWith("Jane"));
    }
}
```

### Parameterized Test Cases (`[TestCase]`)

Passes inline parameters to test multiple input/output permutations:

```csharp
[TestCase(10, 20, 30)]
[TestCase(-5, 5, 0)]
[TestCase(0, 0, 0)]
public void Add_ReturnsCorrectSum(int a, int b, int expected)
{
    var calculator = new Calculator();
    Assert.That(calculator.Add(a, b), Is.EqualTo(expected));
}
```

### Multiple Assertions Block (`Assert.Multiple`)

Executes all assertions in a block, reporting all failures rather than terminating on the first:

```csharp
[Test]
public void ValidateUserRecord()
{
    var user = GetUser();
    Assert.Multiple(() =>
    {
        Assert.That(user.FirstName, Is.EqualTo("Jane"));
        Assert.That(user.LastName, Is.EqualTo("Doe"));
        Assert.That(user.IsActive, Is.True);
    });
}
```

## Common Patterns

### Parameterized Test Fixture with Setup

**Problem**: Redundant boilerplate when testing multiple implementations of the same interface.

**Solution**:
Use `[TestCase]` with typed expectations:

```csharp
using NUnit.Framework;

[TestFixture]
public class CalculatorTests
{
    private Calculator _calculator;

    [SetUp]
    public void SetUp()
    {
        _calculator = new Calculator();
    }

    [TestCase(5, 3, 8)]
    [TestCase(-1, 1, 0)]
    [TestCase(0, 0, 0)]
    public void Add_ReturnsExpectedSum(int a, int b, int expected)
    {
        int result = _calculator.Add(a, b);
        Assert.That(result, Is.EqualTo(expected));
    }
}
```

## Best Practices

**Do**:

- Adopt `Assert.Multiple`: Run all field assertions on complex objects to view full failure contexts simultaneously.
- Use `Assert.That` Exclusively: Modern NUnit deprecates legacy `Assert.AreEqual()` in favor of the constraint model.
- Enable Parallel Execution: Add `[assembly: Parallelizable(ParallelScope.Fixtures)]` to accelerate test execution.
- Pair with FluentAssertions: Combine with `FluentAssertions` library for enhanced assertion readability.

**Don't**:

- Use `[SetUp]` for slow integration setup: Use `[OneTimeSetUp]` for database connections shared across the fixture.
- Leave static shared state unreset: Ensure parallelizable test fixtures do not mutate static state.
- Write huge monolithic test methods: Keep test methods focused on single business behaviors.

## Troubleshooting

| Error                                                              | Cause                                                      | Solution                                                                                     |
| :----------------------------------------------------------------- | :--------------------------------------------------------- | :------------------------------------------------------------------------------------------- |
| `No test is available in ... Make sure test project has reference` | Missing `NUnit3TestAdapter` NuGet package in test project. | Install `NUnit3TestAdapter` and `Microsoft.NET.Test.Sdk`.                                    |
| `AssertionException: Expected: ... But was: ...`                   | Calculation result does not match expectation.             | Check logic and verify constraints using fluent `Assert.That(actual, Is.EqualTo(expected))`. |
| `System.NullReferenceException in SetUp`                           | Accessing uninitialized fixture field in test execution.   | Ensure initialization code is in a `[SetUp]` method, not in standard constructor.            |

## References

- [NUnit Documentation](https://nunit.org/)

Wersje

RepozytoriumWynikLicencja
Ta strona · G1Joshi/Agent-Skills100MIT
managedcode/dotnet-skills100MIT
claude-dev-suite/claude-dev-suite95MIT

Migawka bazy z 13.11.2026 · wersja paczki cc8d4a1baaeb (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95nunit-skill
    Generuje testy jednostkowe w NUnit 3 dla C#, z modelem Assert.That, parametryzacją i mockowaniem Moq.
  • 100xunit
    Wspiera testowanie w xUnit.net dla .NET: testy Fact i Theory, fixtury konstruktora, przechwytywanie wyjścia, testy aplikacji ASP.NET Core i dotnet test.
  • 100dotnet-unit-tests
    Pomaga pisać testy jednostkowe .NET (C#, F#, VB.NET) w xUnit: Fact, Theory z InlineData, fixtury, równoległość, ITestOutputHelper, filtrowanie i dotnet test w CI z raportem trx i pokryciem.
  • 100xunit-nunit
    Projektuje, implementuje i optymalizuje testy jednostkowe i integracyjne .NET w xUnit, NUnit lub MSTest, z mockami i asercjami.
  • 100unity-testing
    Pomaga pisać testy jednostkowe i integracyjne oraz stosować TDD w Unity 6 z atrybutami NUnit, testami MonoBehaviourów i korutyn oraz integracją z CI/CD.
  • 100dotnet-testing
    Pisze testy .NET w xUnit, NUnit lub MSTest, stosując wzorzec Arrange-Act-Assert, atrapy, fabryki danych i testy integracyjne z kontenerami.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.