scaffold-unit-tests

Generates xUnit test classes for CQRS command and query handlers in .NET services.

1|Updated Apr 27, 2026
One-click install
npx skills add https://github.com/GSU26SE55/backend --skill scaffold-unit-tests-gsu26se55
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: scaffold-unit-tests
Source: https://github.com/GSU26SE55/backend/tree/main/.claude/skills/dev/be/scaffold-unit-tests
Command: npx skills add https://github.com/GSU26SE55/backend --skill scaffold-unit-tests-gsu26se55

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing unit tests for every handler of an entity (Create, Update, Delete, Restore, GetList, GetById) is repetitive boilerplate work in a CQRS-based .NET backend, and mocking IQueryable repositories correctly is a common stumbling block. ## Core Features & Use Cases - Test Project Setup: Creates the xUnit test project, adds it to the solution, references the Application project, and installs Moq, FluentAssertions, and MockQueryable.Moq. - Handler Test Scaffolding: Generates command handler tests (success, duplicate, DB error with rollback verification), query handler tests (paging, soft-delete filtering), and validation tests with Theory/InlineData cases. - Use Case: After adding a new Battery entity with its handlers in BatteryService, run the skill to produce a full suite of unit tests following the team's naming and mocking conventions, then verify them with dotnet test. ## Quick Start Ask the AI to scaffold unit tests for a service and entity, for example by running /scaffold-unit-tests BatteryService Battery.

Frequently Asked Questions about scaffold-unit-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for CQRS handlers in .NET?▼

Mock all constructor-injected dependencies such as the Unit of Work and repositories with Moq, then test the happy path, validation failures, and error cases. Use FluentAssertions for result checks and mock.Verify to confirm calls like CommitTransactionAsync.

How to mock IQueryable in Moq unit tests?▼

IQueryable cannot be mocked directly with Moq because it needs a query provider for operations like Where and ToListAsync. Use the MockQueryable.Moq package and call .BuildMock() on an in-memory list to create a valid mock queryable.

What test cases should a command handler unit test cover?▼

Cover the happy path returning success, duplicate or validation failures returning errors, and database exceptions triggering transaction rollback. Verify repository calls with Times.Once or Times.Never and confirm RollbackTransactionAsync runs on errors.

Does this work with xUnit and FluentAssertions?▼

Yes, the generated tests target xUnit with Fact and Theory attributes and use FluentAssertions for readable assertions like result.IsSuccess.Should().BeTrue(). The test project also requires Moq and MockQueryable.Moq packages.

Why does my GetAllAsync mock return null in unit tests?▼

Returning a plain List or a raw AsQueryable() from the mock often fails when the handler calls async LINQ operators. Wrap the data with data.AsQueryable().BuildMock() from MockQueryable.Moq so the in-memory queryable supports the required provider behavior.