Model-based testing
Model-based testing describes expected behavior as a small model. It generates action sequences and compares the real system with the model after each step. It suits anything with history: sessions, retries, lifecycles.ΒΆ
David Khourshid7 described the approach with state machines in Model-Based Testing in React with State Machines. XState builds it into xstate/graph: createTestModel wraps a machine, and getShortestPaths turns it into test paths. βPath generation enables model-based testing - generating test cases directly from your state machine.β Graph & PathsΒΆ
Effect 4βs Arbitrary.array generates command sequences. Its documentation uses a state machine as the example, and failed sequences shrink: the generator removes irrelevant commands to reduce the failing sequence. Arbitrary.tsΒΆ
In rat-stack, the visitor identity model generates visits from three devices. Visits may keep or drop the cookie. Visits also cross day boundaries.ΒΆ
A persistent id survives every visit that keeps its cookie. A daily id stays stable within a day and sets no cookie. It never repeats on a later day. Making the daily hash ignore the day broke the model at once.ΒΆ
Machines in this repo are lifecycles20, so each one is a ready-made test model. See property-based testing18 for single-input rules.ΒΆ
See also: Tests through supplied services22.ΒΆ
Sources
- Model-Based Testing in React with State Machines. David Khourshid Β· CSS-Tricks. Testing article; used for checking action sequences against a model. Accessed 2026-10-01.
- Graph & Paths. David Khourshid Β· Stately docs. Graph docs; used for generated paths from XState machines. Accessed 2026-10-01.
- Effect contributors. 2026. Arbitrary. Effect 4.0.0.. GitHub Effect-TS/effect. Arbitrary API; used for generated and shrinking command sequences. Accessed 2026-10-01.
- rat-stack/packages/events/test/visitor.model.test.ts at main Β· joelhooks/rat-stack Β· GitHub. GitHub joelhooks/rat-stack. Visitor model test; used for identity across cookies, devices, and days. Accessed 2026-10-01.
Last changed 2026-10-07 in f1a00f2. Source on GitHub. Change log.
Linked from
- Agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.
Model-based testing β Describe what a system should do as a small model, generate action sequences, and check the real system against the model.
- Agents explore, tests remember. Let agent users explore scenarios; turn a good bug reproduction into a repeatable test.
Model-based testing generates sequences of actions and checks the system against a model.
- Analytics. One event per HTTP request, stored unchanged for queries to select and interpret later.
The cartridge uses property-based testing and model-based testing.ΒΆ
- Capture first, shape later. Store events without rejecting them for an evolving event shape, then decide their shape when you query.
See property-based testing and model-based testing.ΒΆ
- Change log. What changed in the files served here, newest first.
Model-based testing β edited: feat(learn): teach cards 43 to 62 with plain lines, diagrams and snippets
- Code snippets quote a pinned source. Shipped design brief: pinned Git objects, typed diagnostics, and one build-only snippet model for both views.
See model-based testing and tests that earn their place.ΒΆ
- David Khourshid. David Khourshid teaches state machines with XState and argues for model-based and property-based testing.
Link context
In the testing lesson of his Frontend Masters course on XState, he describes a test model as βa state machine, and the state machine represents all of your given when then statements in a single state machine.β He adds that model-based testing lets you βtest any application whether theyβre using state machines or not.β Testing, State Machines in JavaScript with XState, v2ΒΆ
- Full agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.
- Property-based testing. State a rule that must hold for every input, then let a generator hunt for the smallest input that breaks it.
For sequences of actions, use model-based testing.ΒΆ
- Rat Stack lore | rat-stack. Short, source-grounded notes on the ideas and decisions behind rat-stack.
Model-based testing β Describe what a system should do as a small model, generate action sequences, and check the real system against the model.
- Source change history (log.md). The generated change log as Markdown.
Model-based testing β edited: feat(learn): teach cards 43 to 62 with plain lines, diagrams and snippets
- test-behaviour. Pick the test shape that proves a behaviour. Use when you ask "how do I test this?", add a test, test a domain rule, a lifecycle, a retry, a session, a UI interaction, a timer, or a race, or review a test that might be tautological.
Read model-based testing.ΒΆ
- Tests prove behavior through supplied services. Supply services through Layers, choose properties or models for domain rules, and reject tests that cannot detect broken behavior.
Model-based testing explains the assertions and records the failed day-boundary mutation.
- UI behaviour is a scene. A Foldkit Scene drives update, view, and subscriptions with input and time as plain data, then asserts on what the view shows.
See also: tests that earn their place, model-based testing, and the test-behaviour skill.ΒΆ