Pull up a chair. I want to talk about something that nobody puts on a sprint board but that decides how your next six months will feel: testability. It sounds like a skill you have. It is actually a property of the thing you are testing, a bit like how easy a house is to clean depends on its layout and not only on how hard you scrub.

Two questions define it. Can I put the system into the state I want? And can I see what it did afterwards? Control and observation. Everything else in this article is a variation on those two.

Control: getting into the state you need

Imagine a loan-eligibility feature that behaves differently if the applicant’s account is more than 24 months old. To test the 23-month and 25-month cases you need accounts of those ages. If the only way to get one is to wait two years, or to ask a DBA to edit rows by hand every time, the feature is barely testable. You will test the one account you happen to have and move on.

The fix is rarely clever. The code reads the current date from the system clock directly, so nothing can change it. If instead the code receives “today” from a small clock component, a test can hand it any date it likes. Same story for random numbers, for the current user, for feature flags, for the third-party credit bureau. Each is an input the code currently grabs for itself. Make it an input that is passed in, and tests gain a steering wheel.

Developers call this dependency injection, and you will hear the phrase in design reviews. You do not need to be able to write it. You need to recognise the symptom: a test that needs a real payment gateway, a real SMS provider and a clock you cannot move is a design problem, not a tooling problem.

Observation: seeing what happened

Now the other half. Suppose the system sends a welcome email after sign-up, but it does so in a background job and leaves no trace you can query. Your test clicks Register, and then what? Sleep for ten seconds and check an inbox? That is how flaky tests are born.

Observability is the cure, and it comes in ordinary forms. A status field on the record. A log line that says which rule fired and with which inputs. An API that returns the outcome, not just “accepted”. A test-only endpoint or message queue you can peek into. When a team says “we cannot verify that from outside”, the useful reply is “then what small thing could we expose?”

Be careful, though. Exposing internals purely for tests can be overdone. If you add ten hooks that only tests ever call, you are testing a different system from the one customers use. Prefer observability that operations people would also want, such as structured logs and correlation IDs, because it will be maintained for its own sake.

Smaller pieces are easier to hold

The third ingredient is size. A function that validates input, calculates a premium, writes to the database and sends a notification can only be tested all at once. To check one rule you must set up the whole world. Break it into a pure calculation (numbers in, number out) and thin wrappers that do the I/O, and the calculation can be tested in milliseconds with fifty different inputs.

This is also why architecture affects test strategy. In a monolith with one shared database, you can often test end to end but cannot isolate anything. In many small services, isolation is easy but the joins between them become the risky part, which is why contract tests and service virtualisation exist. Neither is better. They shift where the effort goes.

A rough way to judge testability

When you review a design, or a user story, run through a few questions. They are not a standard, just what tends to expose trouble:

  • Can I create the data I need through an API or script, without a human or a database edit?
  • Does anything depend on time, randomness or an external system I cannot control or replace?
  • After an action, is there somewhere I can read the result that is not just the screen?
  • Can I run this piece alone, or does starting it need the whole environment up?
  • Is the same input going to give the same output tomorrow?
  • Can I reset to a clean state quickly?

Each “no” is a cost you will pay on every future release, and it is cheapest to remove when the design is still on a whiteboard. A one-line comment in a design review, “how will we set the account age in tests?”, costs nothing. The same gap found after launch costs a refactor.

Getting this into the standards

At the level of a whole organisation, testability stops being a conversation and becomes a requirement. Architecture guidelines can say that every service exposes a health endpoint, accepts a correlation ID, reads time and configuration from injectable sources, and provides a way to seed and clean its own test data. Teams then inherit these properties instead of negotiating them story by story.

Notice that none of that is a testing tool. It is just how the software is built. That is the point. A tester who can only work with what has been finished is limited by other people’s decisions. A tester who joins the design conversation, asks the control and observation questions, and is specific about what would help, changes what gets built. That is a much better use of an experienced head than writing a tenth workaround for a clock nobody can move.

One last warning from the other direction. High testability is not the same as high quality. You can build something perfectly controllable and observable that does the wrong thing. Testability only makes the wrongness cheap to discover, which is still a very good deal.

Figures and names in the examples are illustrative.

Leave a Reply

Trending