Dependency Injection - CI/CD Glossary Definition
Dependency injection passes a component its collaborators from outside, so tests can substitute doubles.
Dependency injection is a design technique where a component receives its dependencies from the outside rather than creating them internally. It makes swapping real dependencies for test doubles straightforward.
By accepting dependencies as arguments or configured providers, code becomes decoupled and testable. It is the practical enabler of most unit testing with doubles.
Why it matters for tests
Without injection, a class that news up its own database client is hard to test in isolation. Injection lets a test pass in a fake instead.
Related guides
Inversion of Control - CI/CD Glossary DefinitionInversion of Control: Inversion of control is a principle where the framework or container, rather than your…
Test Double - CI/CD Glossary DefinitionTest Double: A test double is any object that stands in for a real dependency during a test. Mocks, stubs, sp…
Test Isolation - CI/CD Glossary DefinitionTest Isolation: Test isolation means each test runs independently, without depending on or affecting other te…