agentleFS
CripacxCripacx/agentic-dotnet/skills/csharp-nunit/SKILL.md

csharp-nunit

Skill1 starsChanged 9 months agoMITView on GitHub

Get best practices for NUnit unit testing, including data-driven tests

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

34 rules. About 0 are common, 8 are distinctive, and 26 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 26

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use a separate test project with naming convention [ProjectName].Tests

    line 12
  2. Very specific:

    Create test classes that match the classes being tested (e.g., CalculatorTests for Calculator)

    line 14
  3. Very specific:

    Use .NET SDK test commands: dotnet test for running tests

    line 15
  4. Very specific:

    Use [Test] attribute for test methods

    line 20
  5. Distinctive:

    Follow the Arrange-Act-Assert (AAA) pattern

    line 21
  6. Very specific:

    Use [SetUp] and [TearDown] for per-test setup and teardown

    line 23
  7. Very specific:

    Use [OneTimeSetUp] and [OneTimeTearDown] for per-class setup and teardown

    line 24
  8. Very specific:

    Use [SetUpFixture] for assembly-level setup and teardown

    line 25
  9. Distinctive:

    Keep tests focused on a single behavior

    line 29
  10. Distinctive:

    Avoid testing multiple behaviors in one test method

    line 30
  11. Distinctive:

    Use clear assertions that express intent

    line 31
  12. Very specific:

    Use [TestCase] for inline test data

    line 38
  13. Very specific:

    Use [TestCaseSource] for programmatically generated test data

    line 39
  14. Very specific:

    Use [Values] for simple parameter combinations

    line 40
  15. Very specific:

    Use [ValueSource] for property or method-based data sources

    line 41
  16. Very specific:

    Use [Random] for random numeric test values

    line 42
  17. Very specific:

    Use [Range] for sequential numeric test values

    line 43
  18. Very specific:

    Use [Combinatorial] or [Pairwise] for combining multiple parameters

    line 44
  19. Very specific:

    Use Assert.That with constraint model (preferred NUnit style)

    line 48
  20. Very specific:

    Use constraints like Is.EqualTo, Is.SameAs, Contains.Item

    line 49
  21. Very specific:

    Use Assert.AreEqual for simple value equality (classic style)

    line 50
  22. Very specific:

    Use CollectionAssert for collection comparisons

    line 51
  23. Very specific:

    Use StringAssert for string-specific assertions

    line 52
  24. Very specific:

    Use Assert.Throws<T> or Assert.ThrowsAsync<T> to test exceptions

    line 53
  25. Distinctive:

    Use descriptive messages in assertions for clarity on failure

    line 54
  26. Distinctive:

    Consider using Moq or NSubstitute alongside NUnit

    line 58
  27. Distinctive:

    Use interfaces to facilitate mocking

    line 60
  28. Distinctive:

    Consider using a DI container for complex test setups

    line 61
  29. Very specific:

    Use categories with [Category("CategoryName")]

    line 66
  30. Very specific:

    Use [Order] to control test execution order when necessary

    line 67
  31. Very specific:

    Use [Author("DeveloperName")] to indicate ownership

    line 68
  32. Very specific:

    Use [Description] to provide additional test information

    line 69
  33. Very specific:

    Consider [Explicit] for tests that shouldn't run automatically

    line 70
  34. Very specific:

    Use [Ignore("Reason")] to temporarily skip tests

    line 71

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

NUnit Best Practices

Your goal is to help me write effective unit tests with NUnit, covering both standard and data-driven testing approaches.

Project Setup

  • Use a separate test project with naming convention [ProjectName].Tests
  • Reference Microsoft.NET.Test.Sdk, NUnit, and NUnit3TestAdapter packages
  • Create test classes that match the classes being tested (e.g., CalculatorTests for Calculator)
  • Use .NET SDK test commands: dotnet test for running tests

Test Structure

  • Apply [TestFixture] attribute to test classes
  • Use [Test] attribute for test methods
  • Follow the Arrange-Act-Assert (AAA) pattern
  • Name tests using the pattern MethodName_Scenario_ExpectedBehavior
  • Use [SetUp] and [TearDown] for per-test setup and teardown
  • Use [OneTimeSetUp] and [OneTimeTearDown] for per-class setup and teardown
  • Use [SetUpFixture] for assembly-level setup and teardown

Standard Tests

  • Keep tests focused on a single behavior
  • Avoid testing multiple behaviors in one test method
  • Use clear assertions that express intent
  • Include only the assertions needed to verify the test case
  • Make tests independent and idempotent (can run in any order)
  • Avoid test interdependencies

Data-Driven Tests

  • Use [TestCase] for inline test data
  • Use [TestCaseSource] for programmatically generated test data
  • Use [Values] for simple parameter combinations
  • Use [ValueSource] for property or method-based data sources
  • Use [Random] for random numeric test values
  • Use [Range] for sequential numeric test values
  • Use [Combinatorial] or [Pairwise] for combining multiple parameters

Assertions

  • Use Assert.That with constraint model (preferred NUnit style)
  • Use constraints like Is.EqualTo, Is.SameAs, Contains.Item
  • Use Assert.AreEqual for simple value equality (classic style)
  • Use CollectionAssert for collection comparisons
  • Use StringAssert for string-specific assertions
  • Use Assert.Throws<T> or Assert.ThrowsAsync<T> to test exceptions
  • Use descriptive messages in assertions for clarity on failure

Mocking and Isolation

  • Consider using Moq or NSubstitute alongside NUnit
  • Mock dependencies to isolate units under test
  • Use interfaces to facilitate mocking
  • Consider using a DI container for complex test setups

Test Organization

  • Group tests by feature or component
  • Use categories with [Category("CategoryName")]
  • Use [Order] to control test execution order when necessary
  • Use [Author("DeveloperName")] to indicate ownership
  • Use [Description] to provide additional test information
  • Consider [Explicit] for tests that shouldn't run automatically
  • Use [Ignore("Reason")] to temporarily skip tests

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.