๐งช TDD Masterclass
Welcome to the TDD Masterclass! In this tutorial, you'll master the art of test-driven development using ECC's tdd-guide agent.
๐ฏ What is TDD?โ
Test-Driven Development (TDD) is a software development methodology where you:
- ๐ด Red Phase - Write a failing test first
- ๐ข Green Phase - Write the minimum code to make it pass
- ๐ต Refactor Phase - Improve the code without changing behavior
This cycle ensures your code is always tested and you only build what's truly needed.
๐ฎ Try the TDD Commandsโ
ECC Command Simulator
โฏ
Available Commands:
๐ The Red-Green-Refactor Cycleโ
TDD Cycle: Building a Calculator
Step 1 of 41
๐ด Red: Write a Failing Test
First, write a test for functionality that doesn't exist yet. This test must fail.
// calculator.test.ts
import { add } from './calculator'
describe('Calculator', () => {
it('should add two numbers', () => {
expect(add(2, 3)).toBe(5)
})
})๐กRun the test now โ it should fail because add() doesn't exist yet!
๐ป Interactive Code Labโ
Try writing your own TDD cycle! Start with a failing test:
TDD Lab: String Utilitiestypescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
๐ฏ TDD Best Practicesโ
Do โ โ
- Write the smallest possible test first
- Run tests frequently (after every change)
- Commit after each green phase
- Keep refactoring sessions short
- Give tests descriptive names
Don't โโ
- Write implementation code before writing tests
- Write multiple tests at once
- Skip the refactoring phase
- Test implementation details
- Make tests too complex
โ Knowledge Checkโ
โ
In TDD, when should you write implementation code?
โ
What should you do during the refactoring phase?
โ
How long should a typical TDD cycle take?
๐ Congratulations!โ
You've completed the TDD Masterclass! You learned:
- โ The Red-Green-Refactor cycle
- โ TDD best practices
- โ
How to use the
/tddcommand in ECC - โ Writing effective tests
๐ Next Stepsโ
Check out the Interactive Tutorials section for more tutorials!