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

Replace Collaborators

A collaborator is a component your software interacts with. For our purposes, we care about the components that the component under test uses to accomplish its goal. Let’s look at a reworked version of the previous NetRetriever example (Listing 8-8).

In a more realistic example, the connection would be managed separately from the NetRetriever. In addition to supporting the principle of separation of concerns, it abstracts the connection in a way that allows it to be reused and passed in from a larger context. While managing the open and close of the connection may not be the most neighborly or sporting approach in that design context, let’s tolerate it for now.

Listing 8-8: Listing 8-6 rewritten to pass the Connection

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