motis-sim 1.0.0

Fake MOTIS 2 server for tests, serving recorded Transitous responses with injected cancellations, delays and errors
Documentation

motis-sim

A fake MOTIS 2 server for tests. motis-sim serves recorded responses of the MOTIS API on the loopback interface, so a client can be tested end to end without a MOTIS instance and without putting load on a public one like the volunteer-run Transitous.

  • Serves /api/v6/plan, /api/v6/stoptimes, /api/v6/trip, /api/v1/geocode and /api/v1/reverse-geocode (API version v6 of MOTIS v2.11.4). Every request gets the recorded response of its endpoint, whatever the query; other paths answer 404
  • Injects changes on demand: cancelled trips, a cancelled stop of a trip, delays, missing realtime data, any status and body for an endpoint, 429 with Retry-After, slow and malformed responses
  • Records every request with its path, decoded query and User-Agent, so a test can check what was sent, and that nothing was sent

Fixtures

The responses are trimmed answers of the Transitous instance of MOTIS for Frankfurt (Main) on 2026-11-26:

Endpoint Recorded for
plan Hauptbahnhof to Hauptwache, four connections: a direct S4 (DIRECT_TRIP), U5 then U1 with a transfer (FEEDER_TRIP, CONNECTING_TRIP), S5 and S9
stoptimes Six departures at Hauptbahnhof/Münchener Straße, among them the tram 14 (DEPARTURE_TRIP)
trip The S4 of DIRECT_TRIP, Kronberg to Südbahnhof, with its stops
geocode, reverse-geocode Stops for "Hauptwache", and stops near it

The constants name trips of the fixtures to aim injections at. The timetable and realtime data come from the sources listed by Transitous, in Germany from DELFI; place data © OpenStreetMap contributors.

In Rust tests

[dev-dependencies]
motis-sim = "1"
use motis_sim::{DIRECT_TRIP, Injection, Sim};

#[tokio::test]
async fn sees_the_cancellation() {
    let sim = Sim::start().await;
    sim.inject(Injection::Cancel { trip_id: DIRECT_TRIP.into() });
    // Point the client under test at sim.base_url(), like
    // http://127.0.0.1:50123, and query /api/v6/plan.
    let requests = sim.requests();
    assert!(requests.iter().all(|r| r.user_agent.is_some()));
}

Injections stay until Sim::clear(). The sim stops when it is dropped.

In other languages

The binary serves the fixtures until it is interrupted, so tests in any language can start it and point their client at it:

cargo install motis-sim
motis-sim --port 8080

It prints listening on http://127.0.0.1:8080 once it accepts requests and ends with status 0 on Ctrl-C (SIGINT). Without --port it picks a free port. Injections are only available from Rust.

Versioning

motis-sim follows Semantic Versioning from 1.0.0: a breaking change of its public API comes with a new major version only.

License

Apache-2.0

Part of transitous.