AgentSkillsCN

testing

为本项目实施测试驱动开发——包括单元测试、使用 testcontainers 的集成测试、模拟测试,以及回归测试。当您需要编写或修复测试、通过测试重现 Bug,或提升测试覆盖率时,此技能将助您事半功倍。

SKILL.md
--- frontmatter
name: testing
description: Implements Test-Driven Development for this project—unit tests, integration tests with testcontainers, mocks, and regression tests. Use when writing or fixing tests, reproducing bugs with tests, or improving coverage.
version: 1.0

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 using t.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 describe blocks to organize related test cases
  • Each test or it block should test one specific behavior
  • Group related test cases within the same describe block
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

FilePurpose
.cursor/rules/go-testing-practices.mdcGo 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.mdcFrontend testing (React Testing Library, describe/test blocks, MSW), build verification, TypeScript compilation checks
.cursor/rules/test-driven-development.mdcTDD core principles, Iron Law, verification checklist, red flags
.cursor/skills/tdd-workflow/SKILL.mdDetailed TDD workflow with examples, common rationalizations, bug fix walkthrough
.cursor/rules/testing-agent.mdcBug handling and prioritization (critical vs low), bug report template, BUG_NNN naming, systematic testing checklist, when to fix vs when to backlog