Back to blog
8 min readBy VIBPS

How to test software when each action changes what comes next

For APIs, databases, browsers and other persistent systems, make each action’s observation explicit, model the expected state, and treat retries and settling time as part of the test.

TestingSoftware developmentDeveloper guide

A test that changes an external system is never quite starting from zero. Creating a record changes the next query. Clicking a button may start a background job whose result appears later. A browser test can leave a session behind for the next case. When the next step observes a different world because of the previous one, a list of commands and final assertions is not enough: the test needs a clear account of what it observed, what it expected, and why it took the next action.

David Barri describes this problem in his November 30, 2026 post, “Testing Moving Targets.” He proposes treating actions, observations, assertions and expected state as separate pieces, with explicit timing, retries, invariants and useful execution reports. The post is one practitioner's design and account of a Scala testing library, not a comparative study or a universal standard. The ideas below adapt that model to any test suite that interacts with a stateful service.

Give every step an observation boundary

A test often hides its observation inside a helper: click, sleep, then assert that a label changed. Make the boundary visible instead. Describe the action, the point at which the system will be observed, and the fact the assertion can establish. For example: submit an order with a unique test key; repeatedly read that order until its status is confirmed or a deadline expires; then assert that the settled status is paid and that exactly one order exists. The retry belongs to reading the observable result, not blindly repeating the payment.

This distinction matters when state is eventually consistent. A successful write response may mean that a request was accepted, not that every read replica, search index, or browser view has caught up. Pick the observation that answers the question your test is asking. If the contract is that a job is accepted, check the accepted response. If the contract is that a user can see its result, observe the user-facing read path and wait within a bounded deadline. Avoid a fixed long sleep: it is slow when the system is quick and flaky when it is not quick enough.

Keep an expected model beside the real state

For a short scenario, keep a small test-side model of what should happen. If the test adds an item, record its ID and expected owner; if it removes the item, mark it absent. After each meaningful transition, compare a fresh observation with the model. A running balance, a set of created IDs, or a state-machine state can expose a mismatch close to the action that caused it instead of waiting for one vague failure at the end.

The model is a guide for assertions, not another implementation of the application. Keep it simple enough to inspect. State the invariant in terms of the behavior the product promises: a completed request has one result; an account cannot read another account's record; a cancelled operation does not later become successful. When the model merely repeats the production algorithm, the same mistake can appear in both and the test may agree with a bug.

Treat retries as a safety decision

A timeout does not reveal whether the server performed the action. Retrying a read is usually different from retrying a charge, message, or job submission. Before adding retries, identify which operation is repeated, whether it is safe to repeat, and what makes duplicate effects impossible or detectable. An idempotency key may help when the service supports it; otherwise, the test should verify the system's actual duplicate-handling contract instead of assuming one.

Use a short, explicit deadline and record every attempt. When testing delayed systems, retry the observation while leaving a non-idempotent action alone. When testing retry behavior itself, inject the timeout at a controlled boundary and assert both the response and the side effect count. This makes a test explain whether it proved bounded polling, duplicate protection, or merely that one happy-path request worked.

Make order, isolation and cleanup visible

If later actions depend on earlier ones, write the dependency into the scenario rather than relying on test order or shared fixtures. Give each run its own tenant, namespace, account, browser profile, or unique record prefix where possible. Parallel tests against the same mutable resource can otherwise pass alone and fail together. When true isolation is unavailable, serialize the conflicting cases and say so in the test setup.

Cleanup is another state transition and can fail too. Prefer resources that expire automatically, and make cleanup safe to run more than once. Report cleanup errors separately from the assertion that failed; hiding the original mismatch behind a teardown exception makes diagnosis harder. A useful test report names the action, the observation, the elapsed time, the expected state and the state actually seen, while omitting credentials and private data.

Choose a tool that fits the test's question

A queue worker, database-backed workflow and browser UI may need different test tools. The common need is a way to express dependent actions, capture observations, check invariants and make asynchronous waiting understandable. Barri's open-source Scala Test-State library is one example: it composes actions, assertions and observations and can be used with other test frameworks. It is not itself a test framework, and its Scala and Scala.js ecosystem will not fit every project. The design can still be useful even when implemented with ordinary functions in another language.

Start with one awkward scenario that has caused a flaky or misleading test. Write down the action, its side effect, the observation that confirms the result, the invariant to preserve, the timeout policy and the cleanup. Then make the report show those steps. If a teammate cannot tell what the test observed when it failed, the next improvement is probably clearer evidence rather than another retry.

Software testing is also a maker practice: tools for building and sharing apps deserve explanations that make their behavior easier to inspect. VIBPS is a social network for software where makers can introduce an app, find other projects and follow what their creators build next.

Source: David Barri, “Testing Moving Targets,” November 30, 2026

Source: Scala Test-State: project README and usage notes

How to test an AI agent harness before shipping it

Introduce your app on VIBPS

Built around one question: what happens when software becomes easy for almost anyone to create?

Explore apps