Testability is the measure of how easy it is to write a test for the software.

In general, clean code is testable code.

1 Some criteria that can help make code testable

1.1 Pure Functions

Due to their nature, pure functions lend themselves to be tested. Since they do not have any side-effects and are entirely deterministic, only input-output pairs have to be tested with each other. No external dependencies have to be mocked.

1.2 Dependency Injection (Inversion of Control)

If the system under test accepts its dependencies via dependency injection, it is much easier to replace them with a mock. If the SUT doesn’t use dependency injection, imports need to be replaced which tends to be much harder, if not impossible.

2 Backlinks   backlinks