Chuyển đến nội dung
Skillpedia
Kiểm thử48k · #5933

tdd-workflow

Skill này làm gì

Skill này giúp bạn viết code có tổ chức và đáng tin cậy. Nó hướng dẫn bạn qua một chu trình: đầu tiên viết một test thất bại, sau đó viết code tối thiểu để test pass, và cuối cùng cải thiện chất lượng code.

Khi nào nên dùng

  • ✓Khi bắt đầu một tính năng mới.
  • ✓Khi sửa một lỗi.
  • ✓Khi làm việc với logic phức tạp.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd-workflow/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd-workflow/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Giúp tôi áp dụng chu trình TDD để tạo một hàm cộng hai số.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI theo một chu trình: đầu tiên, bạn mô tả code cần làm gì và AI viết một test thất bại. Sau đó, AI viết code đơn giản nhất để test pass. Cuối cùng, AI xem lại và cải thiện code mà không làm hỏng test.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

TDD Workflow

Write tests first, code second.


1. The TDD Cycle

🔴 RED → Write failing test
    ↓
🟢 GREEN → Write minimal code to pass
    ↓
🔵 REFACTOR → Improve code quality
    ↓
   Repeat...

2. The Three Laws of TDD

  1. Write production code only to make a failing test pass
  2. Write only enough test to demonstrate failure
  3. Write only enough code to make the test pass

3. RED Phase Principles

What to Write

Focus Example
Behavior "should add two numbers"
Edge cases "should handle empty input"
Error states "should throw for invalid data"

RED Phase Rules

  • Test must fail first
  • Test name describes expected behavior
  • One assertion per test (ideally)

4. GREEN Phase Principles

Minimum Code

Principle Meaning
YAGNI You Aren't Gonna Need It
Simplest thing Write the minimum to pass
No optimization Just make it work

GREEN Phase Rules

  • Don't write unneeded code
  • Don't optimize yet
  • Pass the test, nothing more

5. REFACTOR Phase Principles

What to Improve

Area Action
Duplication Extract common code
Naming Make intent clear
Structure Improve organization
Complexity Simplify logic

REFACTOR Rules

  • All tests must stay green
  • Small incremental changes
  • Commit after each refactor

6. AAA Pattern

Every test follows:

Step Purpose
Arrange Set up test data
Act Execute code under test
Assert Verify expected outcome

7. When to Use TDD

Scenario TDD Value
New feature High
Bug fix High (write test first)
Complex logic High
Exploratory Low (spike, then TDD)
UI layout Low

8. Test Prioritization

Priority Test Type
1 Happy path
2 Error cases
3 Edge cases
4 Performance

9. Anti-Patterns

❌ Don't ✅ Do
Skip the RED phase Watch test fail first
Write tests after Write tests before
Over-engineer initial Keep it simple
Multiple asserts One behavior per test
Test implementation Test behavior

10. AI-Augmented TDD

Multi-Agent Pattern

Agent Role
Agent A Write failing tests (RED)
Agent B Implement to pass (GREEN)
Agent C Optimize (REFACTOR)

Remember: The test is the specification. If you can't write a test, you don't understand the requirement.

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Câu hỏi thường gặp

“RED”, “GREEN”, “REFACTOR” nghĩa là gì?

“RED” là khi test thất bại. “GREEN” là khi code làm test pass. “REFACTOR” là khi bạn cải thiện code mà vẫn giữ mọi thứ hoạt động.

Vì sao viết test trước code?

Viết test trước giúp bạn biết chính xác code cần làm gì và tránh code thừa.

“YAGNI” là gì?

YAGNI là viết tắt của “You Aren’t Gonna Need It” (bạn sẽ không cần nó). Đây là nguyên tắc chỉ viết code thực sự cần thiết vào thời điểm hiện tại.

Chi tiết

Mô tả gốc của tác giả

Test-Driven Development workflow principles. RED-GREEN-REFACTOR cycle.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#5933
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự