nunit
NUnit testing framework with TestCase, SetUp/TearDown, assertions, and parameterized tests for .NET applications. USE WHEN: user mentions "NUnit", "TestCase", "TestFixture", "NUnit assertions", "NUnit parameterized tests", ".NET NUnit" DO NOT USE FOR: xUnit - use `xunit`, MSTest, JavaScript testing frameworks
What this skill does
# NUnit - Quick Reference
> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `xunit` for .NET testing patterns (concepts transfer).
## Basic Test Structure
```csharp
[TestFixture]
public class UserServiceTests
{
private Mock<IUserRepository> _repository = null!;
private UserService _service = null!;
[SetUp]
public void SetUp()
{
_repository = new Mock<IUserRepository>();
_service = new UserService(_repository.Object, Mock.Of<ILogger<UserService>>());
}
[Test]
public async Task GetById_ExistingUser_ReturnsUser()
{
_repository.Setup(r => r.GetByIdAsync(1))
.ReturnsAsync(new User { Id = 1, Name = "Alice" });
var result = await _service.GetByIdAsync(1);
Assert.That(result, Is.Not.Null);
Assert.That(result!.Name, Is.EqualTo("Alice"));
}
[Test]
public async Task GetById_NonExisting_ReturnsNull()
{
_repository.Setup(r => r.GetByIdAsync(999)).ReturnsAsync((User?)null);
var result = await _service.GetByIdAsync(999);
Assert.That(result, Is.Null);
}
}
```
## Parameterized Tests
```csharp
[TestCase("", false)]
[TestCase("a", false)]
[TestCase("ab", true)]
[TestCase("valid name", true)]
public void IsValidName_ReturnsExpected(string name, bool expected)
{
var result = _validator.IsValidName(name);
Assert.That(result, Is.EqualTo(expected));
}
[TestCaseSource(nameof(GetTestData))]
public void Calculate_ReturnsExpected(int a, int b, int expected)
{
Assert.That(_calculator.Add(a, b), Is.EqualTo(expected));
}
private static IEnumerable<TestCaseData> GetTestData()
{
yield return new TestCaseData(1, 2, 3).SetName("Positive numbers");
yield return new TestCaseData(-1, 1, 0).SetName("Mixed signs");
yield return new TestCaseData(0, 0, 0).SetName("Zeros");
}
```
## Constraint-Based Assertions
```csharp
// Equality
Assert.That(result, Is.EqualTo(42));
Assert.That(name, Is.EqualTo("alice").IgnoreCase);
// Comparison
Assert.That(age, Is.GreaterThan(0).And.LessThan(150));
Assert.That(price, Is.InRange(0m, 1000m));
// Collections
Assert.That(users, Has.Count.EqualTo(3));
Assert.That(users, Has.Exactly(1).Matches<User>(u => u.Name == "Alice"));
Assert.That(names, Is.Ordered.Ascending);
Assert.That(items, Does.Contain("expected"));
// Exceptions
Assert.ThrowsAsync<NotFoundException>(async () => await _service.GetByIdAsync(999));
Assert.That(async () => await _service.CreateAsync(null!), Throws.ArgumentNullException);
// String
Assert.That(message, Does.StartWith("Error").And.Contains("not found"));
```
## SetUp and TearDown
```csharp
[TestFixture]
public class IntegrationTests
{
[OneTimeSetUp] // Runs once before all tests
public async Task OneTimeSetUp() { /* DB setup */ }
[SetUp] // Runs before each test
public void SetUp() { /* Reset state */ }
[TearDown] // Runs after each test
public void TearDown() { /* Cleanup */ }
[OneTimeTearDown] // Runs once after all tests
public async Task OneTimeTearDown() { /* DB teardown */ }
}
```
## Anti-Patterns
| Anti-Pattern | Why It's Bad | Correct Approach |
|--------------|--------------|------------------|
| Classic `Assert.AreEqual` | Less readable | Use constraint model `Assert.That` |
| Shared state between tests | Flaky tests | Reset in `[SetUp]` |
| `[Test]` on async void | Exceptions lost | Use `async Task` return type |
| Too many asserts per test | Hard to identify failure | One logical assertion per test |
## Quick Troubleshooting
| Issue | Likely Cause | Solution |
|-------|--------------|----------|
| Test not discovered | Missing `[Test]` or `[TestFixture]` | Add required attributes |
| SetUp not running | Wrong attribute | Use `[SetUp]` not `[Setup]` |
| Async test ignored | Missing `async Task` | Change return type from `void` |
| TestCaseSource fails | Method not static | Make source method `static` |
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.