O'Reilly logo

Quality Code: Software Testing Principles, Practices, and Patterns by Stephen Vance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Couple Inputs to Outputs

How many times have you seen tests that resemble the following?

assertEquals(4, transformIt(2));

What are the meanings of the literal values 2 and 4 in this code? Sure, you can read the documentation, assuming it exists, for transformIt() and know what it is supposed to do. In the absence of documentation, you can look at the implementation and reverse engineer the code, but then you are testing implementation, not intent. Also, the author of code such as this requires each following developer to decipher his own intent in addition to whatever intent needs to be extracted from the code under test.

Would you rather see something like Listing 5-1 instead?

Listing 5-1: Coupling inputs to outputs in tests

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required