Testing
Testing an application from a plain function call up to a served app on a scripted clock.
An application is built from values, so a test chooses how much of it to start. The cost goes up with each step, and each step catches a different mistake.
| What the test does | Catches | Costs |
|---|---|---|
| Calls a constructor or method directly | Logic in one type | Nothing. |
wire() and reads the error | Missing, ambiguous, cyclic and mis-scoped bindings, before any instance exists | No I/O. |
connect() and app.get::<T>() | Constructors, readiness checks, hooks, module visibility | Builds the singletons. |
| Binds a server on port 0 and sends requests | Routes, extractors, the pipeline | A socket per test. |
| Runs on a scripted clock | Deadlines, drains, backoff | A few lines of setup. |
TestApp is exported from ulo; ulo::testing exports the clock helpers. A constructor-style provider's new is an ordinary function. A test calls it with Dep::from_arc(Arc::new(..)) arguments and no container. Reach for the container when the test is about something it does: visibility, scope, hooks or the wiring itself.
TestApp
The production module graph with values, factories and whole modules replaced.
Clocks in tests
Tokio's paused clock, and ScriptedTimer for apps that own servers.
Asserting failures
Reading wiring, connect and load refusals as data.
Every example under examples/ ships its tests, and the pages here quote them: examples/13-testing is the one about TestApp.
The ex_support helpers in those tests (start, listen, get) belong to the examples workspace (examples/support), not to a published crate. The page for TestApp shows what listen does so a test can write the same three calls.
Moving from axum or actix-web
Move an existing axum or actix-web app onto Ulo one route at a time, with Ulo as the host's fallback service, and a contract test that diffs old and new answers.
TestApp
Replacing a mock, a factory or a whole module in the production graph, and the refusals that keep a stale mock from passing.