Testing Skill
When to use
- •Writing unit or integration tests (Go or frontend)
- •Applying TDD: failing test first, then implementation, then refactor
- •Reproducing a bug with a test before fixing it
- •Creating or updating bug reports when not fixing immediately
- •Improving or verifying test coverage
Test Structure Pattern
Critical Rule: Main test functions must contain subtests.
Go Tests
- •Main test functions (
TestXxx) MUST contain one or more subtests usingt.Run - •Each test case should be a subtest within the main test function
- •Group related scenarios as subtests within the same main test function
- •Use separate main test functions for different behaviors or distinct test groups
go
// ✅ GOOD: Main function contains subtests
func TestNewEmail_WithInvalidInput_ReturnsError(t *testing.T) {
t.Run("returns error for invalid email format", func(t *testing.T) {
// test case
})
t.Run("returns error for empty string", func(t *testing.T) {
// test case
})
}
Frontend Tests
- •Main test suites should use
describeblocks to organize related test cases - •Each
testoritblock should test one specific behavior - •Group related test cases within the same
describeblock
typescript
// ✅ GOOD: Main describe block contains multiple test cases
describe('LoginPage', () => {
test('user can submit login form', async () => { /* ... */ });
test('displays error when email is invalid', async () => { /* ... */ });
});
References
| File | Purpose |
|---|---|
| .cursor/rules/go-testing-practices.mdc | Go testing (testify, t.Run subtests pattern, unit tests with mocks, integration tests with testcontainers), test naming, coverage, test data factories |
| .cursor/rules/frontend-testing-practices.mdc | Frontend testing (React Testing Library, describe/test blocks, MSW), build verification, TypeScript compilation checks |
| .cursor/rules/test-driven-development.mdc | TDD core principles, Iron Law, verification checklist, red flags |
| .cursor/skills/tdd-workflow/SKILL.md | Detailed TDD workflow with examples, common rationalizations, bug fix walkthrough |
| .cursor/rules/testing-agent.mdc | Bug handling and prioritization (critical vs low), bug report template, BUG_NNN naming, systematic testing checklist, when to fix vs when to backlog |