| 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
- ํ
์คํธ ์คํจ๋ฅผ ๋ฌด์ํ๊ณ ์งํ
- "๋์ค์ ํ
์คํธ ์ถ๊ฐํ๊ฒ ์ต๋๋ค"๋ก ๊ฑด๋๋