O'Reilly logo

xUnit Test Patterns: Refactoring Test Code by Gerard Meszaros

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

Appendix ATest Refactorings

Extract Testable Component

Also known as

Sprout Class [WEwLC]

You want to be able to test the logic easily but the component is too closely tied to its context to allow such testing.

Extract the logic you want to test into a separate component that is designed for testability and is independent of the context in which it is run.

Implementation Notes

We extract the logic from the untestable component into a component that is testable via synchronous tests, leaving behind all the ties to the context. This usually means that anything required by the testable component logic from the context is retrieved by the untestable component and passed in to the testable component as arguments of the methods under test or constructor ...

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