
unit-testing
by michaellperry
SKILL.md
name: unit-testing description: Provides unit testing patterns for .NET applications using EF Core In-Memory Provider, AAA structure, test data helpers, and TDD workflows. Use when writing unit tests for services, repositories, or domain logic.
Unit Testing Patterns for .NET
Unit testing patterns for .NET applications covering test structure, EF Core in-memory database setup, test data helpers, and TDD workflows.
TDD Philosophy
TDD is about unit tests only. Unit tests drive implementation using EF Core In-Memory Provider for fast, isolated testing.
Integration tests follow implementation. They use real databases to verify migrations, complex queries, and system integration.
Test Structure
- AAA Pattern: Arrange-Act-Assert with Given-When-Then comments
- Test Naming:
MethodName_Scenario_ExpectedBehavior - Given-When-Then Comments: Describe test flow and intent
EF Core In-Memory Database Setup
Load the resource when configuring DbContext for unit tests, setting up ITenantContext, ensuring per-test database isolation, and understanding provider limitations. See patterns/ef-core-in-memory-setup.md.
Multi-Tenancy Testing
Use the in-memory setup resource for guidance on tenant filtering, admin/null-tenant behavior, and navigation property filter limitations. Load patterns/ef-core-in-memory-setup.md when multi-tenancy affects your tests.
Test Data Helper Patterns
Load the resource when authoring Given helpers: require parent navigation properties for child entities, use sensible defaults for scalars, and avoid foreign keys. See patterns/test-data-helpers.md.
Mocking Strategy
- Use EF Core In-Memory for data operations; avoid mocking data access.
- Mock external dependencies only (email, payment gateways, APIs).
Best Practices
- Use AAA Pattern with Given-When-Then comments
- Follow
MethodName_Scenario_ExpectedBehaviornaming - Initialize navigation properties, never foreign keys
- Make parent entities required parameters in Given methods
- Use in-memory database for repository/service tests
- Mock external dependencies only
- Focus unit tests on business logic
- Use integration tests for navigation property tenant isolation
Resources
- patterns/ef-core-in-memory-setup.md: Load when setting up the in-memory DbContext, tenant context, or needing isolation/limitations guidance.
- patterns/test-data-helpers.md: Load when creating
Givenhelpers, distinguishing required parents vs optional scalars, and avoiding foreign keys. - examples/service-tests.md: Load when you want concrete service test examples using DbContext +
ITenantContextandGivenhelpers. - examples/domain-tests.md: Load when testing domain entities/value objects with invariants and equality.
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です