Saturday, February 8, 2014

Avoid coupling test names to implementation

In our first iteration in the JavaScript Code Retreat, we worked on the rules to tell if a cell goes on living or if a new cell is created having the restriction of not using conditionals.
So we used two very small functions: goesOnLivingWith and isCreatedWith that accepted the number of neighbors as a parameter.

We implemented them using TDD and end up with the following tests:

The main problem with the names of these tests was that they were tightly coupled to the conditions in the rules we had coded:

So we refactored the tests names to improve that:

These new names are much better because they describe the rules focusing in their behavior without getting into details about their implementation.

Avoiding coupling test names with implementation by expressing just behavior will make test names more durable since they won't have to be changed if the implementations undergo any changes.

No comments:

Post a Comment