| name | testing-guide |
| description | Guides test writing with AAA pattern, BVA, EP, and edge case analysis. Use when writing unit tests, integration tests, or infrastructure validation tests. |
Testing Guide
Apply when: "테스트 작성", "테스트 추가", "test", "write test"
Structure (AAA Pattern)
def test_<target>_<condition>_<expected>():
...
...
...
FIRST Principles
- Fast: no external I/O
- Isolated: no dependency between tests
- Repeatable: same result every run
- Self-validating: assert determines pass/fail
- Timely: written with production code
Boundary Value Analysis (BVA)
For any range [min, max], always test:
- min-1, min, min+1, max-1, max, max+1
Equivalence Partitioning (EP)
- Identify valid/invalid partitions
- Pick 1 representative from each partition
- Include: None, empty string, empty list
Coverage Target
- Branch coverage priority (both if/else)
- Exception paths (try/except, raise conditions)
- Normal path + error path
pytest Rules
@pytest.mark.parametrize for multiple inputs
@pytest.fixture for shared setup
pytest.raises() for exception verification
- File:
test_<module>.py
- Function:
test_<target>_<condition>_<expected>()
Mock Rules
- External API, DB, filesystem → Mock
- Pure logic functions → no Mock
- Use
unittest.mock.patch
Test Type Selection
| Request | Test Type |
|---|
| Function/class | Unit test (BVA + EP) |
| Module integration | Integration test |
| Bug fix | Regression test (reproduce bug) |
| API endpoint | Integration + status code |
Checklist (every test)
Edge Case Analysis (5-axis)
Derive edge cases from 5 axes. Pick at least 1 from each applicable axis.
| Axis | Question | Examples |
|---|
| Input | Empty, max length, special chars? | null, 0, MAX_INT, unicode, newline |
| Environment | Disk full, OOM, network down? | DNS fail, read-only mount, low bandwidth |
| State | Initial, mid-failure, post-restart? | uninitialized, partial write, cold start |
| Time | Concurrency, timeout, order reversal? | simultaneous write, expired token |
| Resource | Exhaustion, contention, limit reached? | FD exhausted, pool full, PID limit |
Reference: file:///root/32_system-engineering-resources/01_fundamentals/cs/testing/04_test_design/edge_case_testing.md
Terminology
| Term | Meaning |
|---|
| Edge case | Boundary of valid range |
| Corner case | Multiple boundaries intersecting |
| Degenerate case | Extremely simple/empty input |
| Race condition | Timing-dependent concurrent conflict |
Infrastructure Testing
| 대상 | 검증 명령어 |
|---|
| Terraform syntax | terraform validate |
| Terraform format | terraform fmt -check |
| Terraform plan | terraform plan (No unexpected changes) |
| Ansible syntax | ansible-playbook --syntax-check |
| Ansible dry-run | ansible-playbook --check --diff |
| Shell scripts | shellcheck <script>.sh |
| Shell syntax | bash -n <script>.sh |
IaC Test Principles
terraform plan before every apply
ansible --check before every run
- Idempotency: re-run produces no changes
- Validate after apply: health check, resource state query
- Test failure → switch to
skill://debugging-and-recovery
Container / Docker Testing
| 대상 | 검증 명령어 |
|---|
| Dockerfile lint | hadolint Dockerfile |
| Image build | docker build --no-cache -t test . |
| Container health | docker inspect --format='{{.State.Health.Status}}' |
| Compose syntax | docker compose config |
| Port binding | ss -tlnp 으로 포트 확인 |
Post-Change Verification Pattern
변경 후 반드시 실행하는 검증 순서:
terraform validate && terraform fmt -check
ansible-playbook --syntax-check site.yml
bash -n script.sh && shellcheck script.sh
terraform plan
ansible-playbook --check --diff site.yml
terraform plan
curl -f http://endpoint/health
aws ec2 describe-instance-status --instance-ids <id>
Red Flags
- 테스트 없이 "동작 확인했습니다" 주장
- happy path만 테스트하고 에러 케이스 누락
- edge case 도출 없이 "정상 동작" 판단
- terraform plan 미확인 상태에서 apply
- 테스트 실패를 무시하고 진행
- "나중에 테스트 추가하겠습니다"로 건너뜀