AgentSkillsCN

tdd-workflow

掌握测试驱动开发流程,明晰质量标准,优化工作流路径。适用于测试实践、质量把控,以及各类测试相关工作的指导与规范。

SKILL.md
--- frontmatter
name: tdd-workflow
description: Test-Driven Development process knowledge, quality standards, and workflow guidance

TDD Workflow Skill

Overview

This skill module provides comprehensive TDD workflow guidance, including the RED-GREEN-REFACTOR cycle, quality gates, test patterns, and anti-patterns to avoid.

Note: Examples use Java/Spring Boot conventions (JUnit 5, Gradle). Adapt commands for your stack while following the same patterns.

<essential_principles>

TDD Cycle: RED → GREEN → REFACTOR

  1. RED: Write a failing test that describes the expected behavior
  2. GREEN: Implement the minimum code to make the test pass
  3. REFACTOR: Improve code quality while keeping tests green

Quality Hierarchy

Quality gates are enforced in priority order:

PriorityGateToolThresholdEnforcement
🥇 PRIMARYMutation TestingPIT (pitest)≥80%Blocks merge
🥈 SECONDARYCode CoverageJaCoCo≥80%Blocks merge
🥉 BASELINETests PassJUnit 5100%Always required

Why this order?

  • Code coverage can be 100% with weak assertions (tests run but don't verify)
  • Mutation testing validates that tests actually catch bugs
  • Both together ensure comprehensive, high-quality test suites

Core Testing Principles

  • Test behavior, not implementation: Test what code should do, not how it does it
  • No reflection hacks: Don't test private methods via reflection
  • Test rules, not formulas: "higher values produce larger results" not exact arithmetic
  • Keep test files focused: Split by behavior if tests become unwieldy

</essential_principles>

<intake>

What do you need help with?

TDD Phase:

  1. write - Writing tests first (RED phase)
  2. implement - Making tests pass (GREEN phase)
  3. validate - Running quality gates (coverage + mutation)
  4. refactor - Improving code while keeping tests green (REFACTOR phase)
  5. lookup - Reference information (patterns, commands, anti-patterns)

What phase are you in? (write/implement/validate/refactor/lookup)

</intake> <routing>

Response Routing

ResponseWorkflow/ReferenceDescription
writeworkflows/write-tests-first.mdRED phase - write failing tests
implementworkflows/make-tests-pass.mdGREEN phase - implement code
validateworkflows/validate-coverage.mdRun quality gates
refactorworkflows/refactor-safely.mdREFACTOR phase - improve code
lookup patternsreferences/test-patterns.mdAAA, parameterized tests, factories
lookup commandsreferences/commands.mdTest commands reference
lookup gatesreferences/quality-gates.mdThresholds and enforcement
lookup anti-patternsreferences/anti-patterns.mdWhat to avoid
</routing>

<reference_index>

Reference Files

Workflows

  • workflows/write-tests-first.md - RED phase workflow
  • workflows/make-tests-pass.md - GREEN phase workflow
  • workflows/validate-coverage.md - Quality gate validation
  • workflows/refactor-safely.md - REFACTOR phase workflow

References

  • references/quality-gates.md - Mutation and coverage thresholds
  • references/test-patterns.md - AAA pattern, parameterized tests, factories
  • references/anti-patterns.md - Common anti-patterns to avoid
  • references/commands.md - Test and validation commands

Templates

  • templates/test-file.md - New test file structure
  • templates/describe-block.md - Behavior-organized test structure

</reference_index>

Quick Reference

bash
# CUSTOMIZE: Replace with your project's test commands

# Run tests
./gradlew test

# Run with coverage (JaCoCo)
./gradlew test jacocoTestReport

# Run mutation testing (PIT)
./gradlew pitest