SuperAPI AI Directory

csharp-test-develop

Testing & quality

View repository

Updated 10-16 06:20

About this skill

C# Test Develop

A skill for writing test code for existing C# code. It analyzes code implemented without a TDD workflow and generates tests.

Overview

┌─────────────────────────────────────────────────────────────┐
│  csharp-test-develop (Orchestrator)                         │
│  ├── Phase 0: 환경 감지 ──── test-detector.js 재사용        │
│  ├── Phase 1: 분석 ───────── 대상 코드 → 테스트 시나리오   │
│  └── Phase 2: 검증 ───────── dotnet test 통과 확인          │
├─────────────────────────────────────────────────────────────┤
│  Sub-agent (Executor)                                        │
│  └── 테스트 코드 작성 ────── references/csharp-test-patterns│
│                                                             │
│  ※ csharp-best-practices 규칙 참조 가능                    │
└─────────────────────────────────────────────────────────────┘

Differences from csharp-tdd-develop

Category csharp-tdd-develop csharp-test-develop
Purpose New feature TDD development Add tests to existing code
Workflow Red-Green-Refactor Analyze → Write tests → Verify
Implementation code Written after tests Already exists
Timing Start of development After development / legacy code

Workflow

Phase 0: Environment check

Automatically detect the test environment from the .csproj file.

# csharp-tdd-develop의 test-detector.js 재사용
node skills/csharp-tdd-develop/scripts/test-detector.js --detect

If not installed, guide the user on the required packages and stop.


Phase 1: Analysis

Read the target code and derive test scenarios.

Actions:

  1. Read target file/class
  2. Extract list of public methods
  3. Analyze dependencies (DI interfaces)
  4. Derive test scenarios (normal/exception/edge cases)
  5. Determine test file path

Output:

## 분석 결과

### 대상 클래스
- 이름: OrderService
- 경로: src/Services/OrderService.cs
- 의존성: IOrderRepository, IPaymentGateway, ILogger<OrderService>

### 테스트 시나리오
1. CreateOrderAsync — 유효한 주문 생성 성공
2. CreateOrderAsync — 재고 부족 시 예외 발생
3. CreateOrderAsync — 결제 실패 시 롤백
4. GetOrderByIdAsync — 존재하는 주문 반환
5. GetOrderByIdAsync — 존재하지 않는 주문 null 반환
6. CancelOrderAsync — 이미 취소된 주문 예외

### 테스트 파일
- 경로: tests/UnitTests/Services/OrderServiceTests.cs

Phase 2: Write tests (delegate to subagent)

Delegate via Task tool:

Task({
  subagent_type: "general-purpose",
  prompt: `
기존 코드에 대한 단위 테스트를 작성하세요.
SOLID 원칙, GoF 디자인 패턴, Modern C# 12/13 기능을 적용하세요.

## 대상
- 클래스: OrderService
- 경로: src/Services/OrderService.cs
- 테스트 파일: tests/UnitTests/Services/OrderServiceTests.cs

## 테스트 시나리오
1. CreateOrderAsync — 유효한 주문 생성 성공
2. CreateOrderAsync — 재고 부족 시 예외 발생
...

## 테스트 패턴 (필수 적용)
- AAA Pattern (Arrange-Act-Assert)
- 네이밍: Method_Scenario_ExpectedBehavior
- Moq로 의존성 Mock
- FluentAssertions 사용 (설치된 경우)
- xUnit Theory/InlineData (매개변수화 테스트)

## 지침
1. references/csharp-test-patterns.md 패턴 적용
2. 테스트 실행하여 **통과 확인** (dotnet test)
3. 테스트 결과 리포트
`
})

Phase 3: Verification

  • Confirm test pass from the agent response
  • Request fixes on failure (up to 3 times)
  • Output coverage report (if coverlet is installed)

Currently passed arguments

ARGUMENTS: $ARGUMENTS

Execution instructions

The above ARGUMENTS is a description of the target class/file for which to write tests.

If ARGUMENTS is empty ask the user for the test target.

Invocation examples:

  • /csharp-test-develop src/Services/UserService.cs → Write tests for that file
  • /csharp-test-develop OrderService → Find the OrderService class and write tests

Execution example

Request

"Write unit tests for OrderService"

Execution flow

## Phase 0: 환경 확인
Runner: xUnit ✓ | FluentAssertions: YES ✓ | Moq: YES ✓

---

## Phase 1: 분석
- 클래스: OrderService
- public 메서드 3개
- 의존성 3개 (모두 인터페이스)
- 시나리오 6개 도출

---

## Phase 2: 테스트 작성
→ 서브에이전트 호출
← 테스트 파일 생성, 모든 테스트 통과 ✅

---

## 완료!
- tests/UnitTests/Services/OrderServiceTests.cs (6 tests)

Test file path rules

Path determination criteria: Repository/Database access code → IntegrationTests, the rest → UnitTests

Source location Test location
src/Services/UserService.cs tests/UnitTests/Services/UserServiceTests.cs
src/ViewModels/MainViewModel.cs tests/UnitTests/ViewModels/MainViewModelTests.cs
src/Repositories/UserRepository.cs tests/IntegrationTests/Repositories/UserRepositoryTests.cs

Error Handling

Situation Handling
Test runner not installed Output installation command and stop
Target file not found Ask the user to confirm the path
Test failure Attempt fixes up to 3 times, then ask the user for help

Delegation structure

csharp-test-develop (Orchestrator)
    │
    └── general-purpose sub-agent
            │
            └── 참조 가능 리소스:
                  ├── csharp-best-practices/rules/ ← C# 12 규칙 (필요시 Read)
                  └── references/
                        └── csharp-test-patterns.md ← 테스트 패턴 (필요시 Read)

Resources

references/

  • csharp-test-patterns.md: C# test pattern guide (AAA, Moq, FluentAssertions, etc.)