Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
Python & Django

Confidence in Code That Runs Unattended

Last updated:

Unattended code needs different testing

A web application has users who report problems. A service running overnight has nobody watching, which means its failure handling matters more than its normal operation.

The question is not whether it works with good input. It is what happens with the record that has a null where a date should be, at three in the morning.

What to test

  1. Transformations — the logic that turns input into output
  2. Boundaries — what happens with empty, huge, malformed input
  3. Failure paths — external service down, timeout, bad response
  4. Idempotency — running the same thing twice
  5. Reconciliation — the counts add up

Test against real data shapes

  • Use anonymised production samples, including the awkward ones
  • Include the record that broke it last time
  • Test with an empty input set
  • Test with a volume larger than you expect
  • Test with a deliberately corrupted input

Synthetic clean test data tests the code you wrote against the assumptions you made, which is the least useful thing to verify.

Mock the boundary, not the logic

MockDo not mock
External API callsYour own transformations
Time, where behaviour depends on itDatabase queries in integration tests
RandomnessThe logic under test
Slow third-party servicesAnything you actually want verified

Run them automatically

Tests that require someone to remember stop being run. They should execute on every push, with a visible result, blocking a merge on failure.

That is a day of setup and it is what turns a test suite into a working safety net rather than a good intention.

Frequently asked questions

How much coverage is enough?

Enough to change the code confidently. That is usually the transformations and the failure paths, not every line.

Should tests hit a real database?

For integration tests, yes — a test database. Mocking the database tests your mocks.

How do we test external integrations?

Contract tests against recorded responses, plus a periodic check against the real service to detect changes.

What about testing machine learning code?

Test the data handling and the feature computation. Model quality is evaluated statistically, which is a different exercise.

Keep reading

Service that runs overnight and sometimes does not?

Its failure paths are probably untested. That is where the tests are worth writing.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Custom Software DevelopmentWeb DevelopmentMachine Learning