dotnet-testing-unit-test-fundamentals_skill

This skill helps you implement .NET unit testing fundamentals with FIRST principles, AAA pattern, and xUnit guidance to improve test quality.
  • C#

19

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill kevintsengtw/dotnet-testing-agent-skills --skill dotnet-testing-unit-test-fundamentals

  • SKILL.md9.1 KB

Overview

This skill teaches .NET unit testing fundamentals and how to apply the FIRST principles and the Arrange-Act-Assert (AAA) pattern. It focuses on writing clear, fast, and maintainable xUnit tests, naming conventions, parameterized tests, exception testing, and recommended project structure. Use it to create, evaluate, or improve unit tests that are reliable and easy to maintain.

How this skill works

The skill inspects your .NET methods and suggests test cases that cover normal paths, edge cases, invalid inputs, and expected exceptions. It recommends xUnit attributes ([Fact], [Theory], [InlineData]) and enforces the AAA pattern for every test. It also validates tests against the FIRST criteria (Fast, Independent, Repeatable, Self-validating, Timely) and suggests project layout and csproj dependencies for a proper test project.

When to use it

  • When creating unit tests for a new or existing .NET class or method
  • When improving test quality, readability, or execution speed
  • When designing parameterized tests with multiple input combinations
  • When documenting test naming and asserting best practices
  • When setting up a test project with xUnit and proper dependencies

Best practices

  • Follow FIRST: keep tests fast, independent, repeatable, self-validating, and timely
  • Structure each test using Arrange-Act-Assert and test one behavior per test
  • Use descriptive test names: MethodName_Scenario_ExpectedBehavior
  • Prefer [Fact] for single cases and [Theory]+[InlineData] for data-driven cases
  • Avoid external I/O or shared mutable state; mock or isolate dependencies
  • Cover normal paths, boundaries, invalid inputs, and exception scenarios

Example use cases

  • Write Add_Inputs1And2_Returns3 using Arrange-Act-Assert and Assert.Equal
  • Convert multiple similar tests into a [Theory] with [InlineData] for coverage
  • Test Divide_Inputs10And0_ThrowsDivideByZeroException and assert message
  • Refactor brittle tests to remove shared state so each test is independent
  • Create a tests/ project with xUnit, coverlet, and Microsoft.NET.Test.Sdk references

FAQ

[Fact] is for a single scenario. Use [Theory] with [InlineData] for the same behavior across multiple input sets.

How many assertions should a test contain?

Aim for one primary assertion per test to verify a single behavior. Additional assertions can be used for related state checks, but keep tests focused.

How do I test exceptions cleanly?

Use Assert.Throws<T>(() => method()) to assert the exception type, and verify the exception message if message content matters.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
dotnet-testing-unit-test-fundamentals skill by kevintsengtw/dotnet-testing-agent-skills | VeilStrat