AgentSkillsCN

tdd-workflow

在编码前制定测试计划,以确保代码的高质量与高可靠性。

SKILL.md
--- frontmatter
name: tdd-workflow
description: A structured methodology for writing tests before code to ensure high quality and reliability.

Skill: TDD Workflow

This skill enforces a discipline of writing automated tests before implementation code.

🔄 The Red-Green-Refactor Cycle

  1. RED: Write a failing unit test for a specific requirement.
  2. GREEN: Write the minimal amount of implementation code to make the test pass.
  3. REFACTOR: Clean up the implementation and the test code while keeping the test passing.

📋 Coverage Targets

  • Aim for at least 80% code coverage for business logic and utilities.
  • Focus tests on behavior, not implementation details.

🛠️ Tooling

  • Frontend: Vitest / Jest / Playwright.
  • Backend: Rust's built-in #[test] and tokio::test.

📄 Example: TDD Step

typescript
// 1. Red (Test)
test('add(1, 2) returns 3', () => {
  expect(add(1, 2)).toBe(3); // Fails: add is undefined
});

// 2. Green (Code)
const add = (a, b) => a + b;

// 3. Refactor
// (Optimize or clean up name if needed)