Programming foundations

Stage 5 · Lesson 7 of 10

Test-driven development

Object-oriented design and clean code

flips the usual order. First write a failing for the next small behaviour. Then write just enough code to make it pass.

Then clean up the code while the tests stay green (passing). This cycle is called red, green, refactor, and each round takes a few minutes. It forces you to decide what a should do before how.

It keeps each step small, and it leaves tests behind for everything you built. You do not need it for every line. It works very well for logic with clear rules, such as pricing or validation.

It also works well for bugs: write a test that reproduces the bug, then fix it, so it never comes back. Safe refactoring depends on this safety net.

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

Practise

  • Request mentoring on a solved exercise and ask specifically about naming and structure

Keep handy

Also worth your time

Mark this stage as not done?