© Khaled El-Morabea and Hassaan El-Garem 2021
K. El-Morabea, H. El-GaremModularizing Legacy Projects Using TDDhttps://doi.org/10.1007/978-1-4842-7428-6_7

7. Dependency Injection and Mocks

Khaled El-Morabea1   and Hassaan El-Garem2
(1)
Giza, Egypt
(2)
Cairo, Egypt
 

Writing tests for a component can be a tedious task if this component depends on another component that has an unpredictable behavior. To test such a component, we need to be able to control this unpredictable behavior. We can do that with the help of a test double. The term test double was first introduced in Gerard Meszaros’s book XUnit Test Patterns. Test double is a generic term for any kind of pretend object used in place of a real object for testing purposes. Another situation in which ...

Get Modularizing Legacy Projects Using TDD: Test-Driven Development with XCTest for iOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.