Book Image

Test-Driven Java Development

Book Image

Test-Driven Java Development

Overview of this book

Table of Contents (17 chapters)
Test-Driven Java Development
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
8
Refactoring Legacy Code – Making it Young Again
Index

Chapter 3. Red-Green-Refactor – from Failure through Success until Perfection

 

"Knowing is not enough; we must apply. Willing is not enough; we must do."

 
 --Bruce Lee

The red-green-refactor technique is the basis of TDD. It is a game of ping pong in which we are switching between tests and implementation code at great speed. We'll fail, then we'll succeed and, finally, we'll improve.

We'll develop a Tic-Tac-Toe game by going through each requirement one at a time. We'll write a test and see if it fails. Then, we'll write a code that implements that test, run all the tests, and see them succeed. Finally, we'll refactor the code and try to make it better. This process will be repeated many times until all the requirements are successfully implemented.

We'll start by setting up the environment with Gradle and JUnit. Then, we'll go a bit deeper into the red-green-refactor process. Once we're ready with the setup and theory, we'll go through the high-level requirements of the application.

With everything...