

Programmers who incorporate unit testing into their development process inevitably hit what we call the testing wall; this is the point where your code becomes too hard to test in isolation. You've hit the testing wall if you've ever thought:
In Part 1 of this series, you wrote code and tests for the initial implementation of a Twitter client. The code worked; the tests passed. However, you took a brute force approach when writing the unit tests: Most of the tests depended on the availability of the Twitter service. This resulted in slow tests, and slow tests mean productivity loss. In addition, the testing ignored error paths because the component design didn't lend itself to easily testing what happens when calls to the Twitter service fail.
In Part 2 of this series, you'll refactor the Twitter client code and its tests to create a more robust and easily testable API. You'll do this by applying strategies for decoupling external dependencies from business logic so that those dependencies can be swapped with test-friendly stand-ins (known as mocks) during test execution. In addition, you'll see how components that are easier to test are often easier to use in the context of an application.
In order to make the most of this article, you need the following software and files:
Working knowledge of ColdFusion Components, some experience writing unit tests for ColdFusion, and knowledge of the concepts covered in Part 1 of this series.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
Bill Shelton is the blurred visionary for the MXUnit framework and part-time software quality evangelist. He has been building web software since the time CGI and Perl were considered really cool and has been using ColdFusion, Java, and other languages for more than 10 years. Bill lives in Northern Virginia with his wife and kids, and works for the U.S. Federal Government.
Marc Esher has been developing ColdFusion and Java applications since 2000. He currently works in the financial industry building custom print-on-demand software. He is a co-project-owner for MXUnit and has contributed the Eclipse plugin along with several framework features. He has an abiding passion for team building, mentoring, and process improvement. Marc lives in Pennsylvania with his wife and children.
Marc and Bill blog occasionally at http://blog.mxunit.org and can be followed on Twitter: Bill Shelton@virtix. Marc Esher@marcesher