Fault injection

Fault injection makes a dependency misbehave on purpose so the code that depends on it can be tested against the failures it will eventually meet: slow answers, intermittent 5xx errors, timeouts, malformed bodies. It is the controlled, repeatable end of the spectrum that runs up to chaos engineering in production.

How it works

Faults are injected at a boundary the code under test cannot see past — a mock server, a proxy, a service mesh rule, a feature flag in the dependency itself. The test then asserts on behaviour: that retries happen and stop, that a timeout fires, that a fallback is shown, that no half-written state is left behind.

The misconception

That random failures make a good test. A test that fails one run in four is a flaky test. Useful fault injection is deterministic — this request fails, that one is slow — or at least seeded, so a failure can be reproduced and a fix verified.

Try it here

The Fault Injection API is configured with PUT /faults/v1/config — latency, a status code, a failure rate, malformed JSON — and GET /faults/v1/target then misbehaves exactly as configured, inside your own sandbox.

Sources

Other terms

All glossary terms · Testing techniques · All 39 mock REST APIs

Last updated