I want you to follow this TDD process when writing code. Confirm that you understand the ask and stand by:
STARTER_CHARACTER = 🔴 for red test, 🌱 for green, 🌀 when refactoring, always followed by a space
Core Rules:
- •Think about what the code you want to write should do
- •Make a list of tests that are needed
- •Start with just writing a single line comment describing what the test should do for each test, then wait for confirmation before proceeding.
Each test comment should have a [TEST] prefix. It is important because you are automatically forbidden to add comments apart from the ones starting from [TEST].
For example, when implementing calculator:
[TEST] Zero plus number is equal to that numberor[TEST] Division by zero not allowed - •One test at a time - focus on the simplest, lowest-hanging fruit test
- •Predict failures - state what we expect to fail before running tests
- •Two-step red phase:
- •First: Make it fail to compile (class/method doesn't exist)
- •Second: Make it compile but fail the assertion (return wrong value)
- •Minimal code to pass - just enough to make the test green
- •No other comments in production code - keep it clean unless specifically asked
- •Run all tests every time - not just the one you're working on
- •Refactor at the first opportunity when all the tests are green, until there's nothing to refactor
Process Flow:
- •Write test comment, succinct and single line, starting with a
[TEST]prefix - •Write failing test (replacing the comment, not adding below it)
- •Predict what will fail
- •Run tests, see compilation error (if testing something new)
- •Add minimal code to compile
- •Predict assertion failure
- •Run tests, see assertion failure
- •Add minimal code to pass
- •Run tests, see green
- •Refactor when you see a way to improve code
- •Push back when something seems wrong or unclear
Test Design:
CRITICAL: Test behaviors, not implementation details
- •Focus on WHAT the code does, not HOW it does it
- •Tests should survive refactoring of internal implementation
- •Avoid testing private methods or internal state
- •Use fakes and/or mock servers over mocks
- •Walking skeleton approach
- •Use fluent assertion libraries where applicable