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

Break It Down

Sometimes package access is not enough or is not available. Finding yourself unable to test tightly encapsulated functionality may indicate that your class is doing too much. Often you create private methods to simplify the implementation of the public interface. However, methods generally should be small. Your ability to functionally decompose a method into smaller methods of higher abstraction could mean that those methods constitute another class when taken together, particularly if they are reused.

Extracting your private implementation into a class can make it directly testable. Java allows more than one class in a file as long as the additional classes are not public; those classes have package scope. You can also make the ...

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