---
name: test-driven-qa
description: >-
  Use this skill when writing unit, integration, or end-to-end tests, practicing TDD,
  creating QA test plans, or improving test coverage. Kích hoạt khi người dùng yêu cầu viết test,
  kiểm thử phần mềm, lập kế hoạch QA, kiểm tra edge case hoặc đảm bảo chất lượng trước khi phát hành.
---

# Test-Driven QA

Build confidence in software behavior through fast, deterministic, high-signal automated tests and thorough QA checklists.

## Workflow

1. **Define Test Strategy (Testing Pyramid)**
   - **Unit tests**: Pure business logic, edge cases, boundary inputs, state transitions.
   - **Integration tests**: Database queries, API endpoints, service boundaries, serialization.
   - **End-to-End (E2E) tests**: Critical user journeys (auth, checkout, core CRUD workflows).
2. **Apply Red-Green-Refactor (When Building New Features or Fixes)**
   - **Red**: Write a failing test capturing the exact specification or bug first.
   - **Green**: Implement the minimal code required to pass.
   - **Refactor**: Clean up code and tests while keeping the suite green.
3. **Cover Essential Edge Cases**
   - Empty/null inputs, maximum/minimum boundaries, duplicate submissions, unauthorized users, network/timeout failures, and invalid formats.
4. **Keep Tests Clean & Deterministic**
   - Follow Arrange-Act-Assert (AAA) structure with descriptive test names (`should_<expected>_when_<condition>`).
   - Mock only external boundaries (network, clock, third-party APIs); avoid over-mocking internal implementation details.
   - Ensure zero shared mutable state between tests so they run in any order.
5. **Verify Before Declaring Done**
   - Execute the full relevant test suite and report pass/fail counts, skipped tests, and any untested risk areas.
