DEV Community

Discussion on: When do you write your tests?

Collapse
jjjjcccjjf profile image
endan

It's the first time I heard of "red-green-refactor" catchphrase, but isn't it supposed to be "red-refactor-green"? 😅

Collapse
bobbypriambodo profile image
Bobby Priambodo

I believe it's really red-green-refactor, as Wikipedia and several other articles confirm:

Each test case fails initially: This ensures that the test really works and can catch an error. Once this is shown, the underlying functionality can be implemented. This has led to the "test-driven development mantra", which is "red/green/refactor", where red means fail and green means pass. Test-driven development constantly repeats the steps of adding test cases that fail, passing them, and refactoring.

The principle is that, if we're in the red, it's not possible to refactor confidently, because you don't know whether the current code to be refactored is correct, or even exists at all!

Thread Thread
jjjjcccjjf profile image
endan

I understand now. Thanks for your explanation!