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

The TDD implementation of Connect4


At this time, we know how TDD works: writing tests before, implementation after tests, and refactoring later on. We are going to pass through that process and only show the final result for each requirement. It is left to you to figure out the iterative red-green-refactor process. Let's make this more interesting, if possible, by using a Hamcrest framework in our tests.

Hamcrest

As described in Chapter 2, Tools, Frameworks, and Environment, Hamcrest improves our tests readability. It turns assertions more semantic and comprehensive at the time that complexity is reduced by using matchers. When a test fails, the error shown becomes more expressive by interpreting the matchers used in the assertion. A message could also be added by the developer.

The Hamcrest library is full of different matchers for different object types and collections. Let's start coding and get a taste of it.

Requirement 1

We will start with the first requirement.

Note

The board is composed...