Students will practice describing and applying the three steps of the Test-Driven Development (TDD) cycle—Red, Green, and Refactor—by collaboratively planning and documenting their process for implementing a simple feature. This activity emphasizes understanding the purpose and flow of each step.
- In small groups, discuss the three steps of TDD: Red, Green, and Refactor.
- Each group should create a brief summary (1–2 sentences per step) explaining:
- What happens during each phase.
- Why it is important.
You are tasked with implementing a countVowels
function that takes a string and returns the number of vowels (a
, e
, i
, o
, u
) in the string.
- Write a failing test case for the
countVowels
function. - Describe:
- What behavior you want to test.
- Why the test is expected to fail initially.
- Document expected output for various inputs:
"hello"
→ ?"world"
→ ?""
→ ?
- Explain:
- Why starting with a failing test clarifies the function’s requirements.
- Brainstorm the simplest code that could make the test pass.
- Document implementation ideas.
- Focus only on meeting the test’s expectations.
- Discuss:
- Why it’s important to prioritize functionality over optimization in this step.
- Once the test passes:
- Identify ways to improve the code’s readability, efficiency, or maintainability.
- Propose specific refactoring steps.
- Explain how those steps improve the implementation.
- Reflect:
- Why this step is critical for long-term project success.
Each group will present:
- ✅ Their summaries of the Red, Green, and Refactor steps.
- 🔴 The failing test they wrote during the Red phase and their reasoning.
- 🟢 The minimal code they proposed during the Green phase and how it aligns with the test.
- 🔵 The refactored code they designed and the benefits of their improvements.