generating-tests
Generating Tests
Generate xUnit tests for C#/.NET ABP Framework projects.
Quick Start
# Analyze source and generate tests
python scripts/generate_tests.py src/MyAppService.cs --type unit
Workflow
Copy this checklist and track progress:
Test Generation Progress:
- [ ] Step 1: Locate source file
- [ ] Step 2: Analyze public methods and dependencies
- [ ] Step 3: Select template based on source type
- [ ] Step 4: Generate test file
- [ ] Step 5: Validate generated tests compile
Step 1: Locate source
| Input | Action |
|---|---|
| File path | Read directly |
| Class name | find api/src -name "*ClassName*.cs" -type f |
gaps |
Run scripts/find_coverage_gaps.py |
Step 2: Analyze source
Extract from each public method:
- Method signature (name, parameters, return type)
- Constructor dependencies → mock with
Substitute.For<T>() [Authorize]attributes → add 401/403 test cases- FluentValidation rules → add validation error tests
Step 3: Select template
| Source Pattern | Reference |
|---|---|
*AppService.cs |
See reference/appservice-tests.md |
*Validator.cs |
See reference/validator-tests.md |
*Controller.cs |
See reference/integration-tests.md |
Step 4: Generate and write
Output locations:
- Unit tests:
api/test/[Module].Application.Tests/[Class]Tests.cs - Integration tests:
api/test/[Module].HttpApi.Tests/[Class]IntegrationTests.cs
Step 5: Validate
dotnet build api/test/[Module].Application.Tests/
If build fails, fix compilation errors and rebuild.
Test Naming
Use pattern: [Method]_[Scenario]_[Expected]
| Example | Meaning |
|---|---|
Create_ValidInput_ReturnsDto |
Happy path |
Create_MissingName_ThrowsValidation |
Validation failure |
Get_NotFound_ThrowsException |
Entity not found |
Delete_Unauthorized_Returns403 |
Permission denied |
More from thapaliyabikendra/ai-artifacts
abp-infrastructure-patterns
ABP Framework cross-cutting patterns including authorization, background jobs, distributed events, multi-tenancy, and module configuration. Use when: (1) defining permissions, (2) creating background jobs, (3) publishing/handling distributed events, (4) configuring modules.
59clean-code-dotnet
Clean Code principles adapted for C#/.NET including naming, variables, functions, SOLID, error handling, and async patterns. Use when: (1) reviewing C# code, (2) refactoring for clarity, (3) writing new code, (4) code review feedback.
52abp-entity-patterns
ABP Framework domain layer patterns including entities, aggregates, repositories, domain services, and data seeding. Use when: (1) creating entities with proper base classes, (2) implementing custom repositories, (3) writing domain services, (4) seeding data.
51abp-api-implementation
Implement REST APIs in ABP Framework with AppServices, DTOs, pagination, filtering, and authorization. Use when building API endpoints for ABP applications.
46abp-service-patterns
ABP Framework application layer patterns including AppServices, DTOs, Mapperly mapping, Unit of Work, and common patterns like Filter DTOs and ResponseModel. Use when: (1) creating AppServices, (2) mapping DTOs with Mapperly, (3) implementing list filtering, (4) wrapping API responses.
44abp-contract-scaffolding
Generate ABP Application.Contracts layer scaffolding (interfaces, DTOs, permissions) from technical design. Enables parallel development by abp-developer and qa-engineer. Use when: (1) backend-architect needs to generate contracts, (2) preparing for parallel implementation workflow, (3) creating API contracts before implementation.
36