Iron rule: Tests must prove behavior, not mechanically replicate implementation details.
Workflow
- Step 1: Understand the object under test ⚠️ REQUIRED
- 1.1 First read the source code and existing tests to identify key branches and dependencies.
- 1.2 Determine whether it is more appropriate to write unit, integration, or higher-level verification.
- Step 2: Design the test set ⚠️ REQUIRED
- 2.1 Cover at least the main flow, failure paths, and boundary conditions.
- 2.2 Confirm which dependencies need to be mocked and which are more suitable for real calls.
- Step 3: Implement tests
- 3.1 Test descriptions should focus on business behavior and expected results.
- 3.2 Avoid excessive coupling to internal implementation details.
- Step 4: Execute and explain results
- 4.1 Run the most relevant test command.
- 4.2 When it fails, first explain the root cause, then decide whether to change the code or change the test.
Focus points
- Whether the test naming explains the behavior.
- Whether mocks mask real integration risks.
- Whether boundary conditions cover null values, exceptions, and ordering issues.
- Whether regression protection was added for new features.
Project-specific tips
- If the repository already has tests/testSetup.ts or a global mock entry point, reuse it first; do not reinvent the wheel in every test.
- When frontend logic is involved, prioritize controllable mocks for useI18n, routing, and external requests.
- Before writing tests, first verify the actual test commands and run methods that exist in package.json.
Anti-patterns
- Testing only the happy path.
- Replacing key business assertions with snapshots or internal implementation assertions.
- Directly changing assertions to make them green when tests fail.
Pre-delivery checklist
- The main flow, failure paths, and boundary scenarios are covered.
- Test assertions reflect business behavior rather than internal details.
- Relevant tests have been run, or the reason they were not run has been clearly stated.
- If test gaps remain, they have been clearly pointed out.