TDD in Legacy Code - Component Testable Architecture
Legacy Code might be tangled up so that it might not be Component Testable, which prevents us from introducing Component Tests & Contract Tests. We need Component Testable Architecture.
📅 Join 100+ engineers at my next FREE live event Stop Breaking Production: ATDD in Legacy Code (Sep 17 at 5:00 PM CET)
🔒Hello, this is Valentina with a premium issue of the Optivem Journal. I help Engineering Leaders & Senior Software Developers apply TDD in Legacy Code. This article is part of the TDD in Legacy Code series.
Legacy Code might not be Component Testable
In Acceptance Testable Architecture in Legacy Code, we covered the problem where a System is not Acceptance Testable, whereby it’s statically coupled to External Systems, which included the following cases:
Hard-coded connections to External HTTP APIs
Static calls to the System Clock and other non-deterministic sources
Static calls to complex external libraries
Aside from the problem of static coupling between our System and External Systems, Legacy Code also often has the problem of static coupling within our System, between the Components themselves:
Hard-coded connections from Frontend to Backend
Hard-coded connections between Microservices
We can’t introduce Component Tests
To write Component Tests, we need to have Component Dependency Stubs. For example: (1) to write Component Tests for the Frontend, we need to be able to stub out the Backend, (2) to write Component Tests for Microservice #1, and assuming Microservice #1 depends on Microservice #2 and Microservice #3, we then need to stub out those dependent microservices.
We need Component Dependency Stubs because they enable us to test our Component in isolation.
At runtime, to switch between Real Component Dependencies and Component Dependency Stubs, we need Component Dependency Configurability.
So we need to ensure Component Testable Architecture
That’s why we need to make some changes to our source code to ensure Component Dependency Configurability.
But how do these changes… without risking the whole system?
Here are the steps for achieving Component Testable Architecture in Legacy Code. You’ll get tasks to implement in your GitHub Sandbox Project. ⬇️⬇️⬇️