Skip to content
Latchkey

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

Run this faster and cheaper on Latchkey managed runners. Start free →