What if writing tests was a joyful experience?
Expect tests (snapshot tests) let you write a blank `[%expect]` block under code that prints output; the test runner fills in the actual output as a diff you can accept in your editor, making test-writing feel like a REPL session. Jane Street uses them for most of its OCaml test suite, from rounding-function tables and Bonsai web UI DOM diffs to magic-trace symbol demangling and order-book state machines. Because they capture whole printed state rather than hand-picked assertions, they implicitly guard against regressions you didn't anticipate. Good expect tests depend on helper functions and pretty-printers that keep the output concise and readable.
Related posts
- What the interns have wrought, 2022 edition
Jane Street Tech Blog mediumAdeptThree Jane Street intern projects from 2022 show substantial tooling work in OCaml. magic-trace gained a sampling mode that can cover 20 seconds to 20 minutes on Intel or AMD hardware, plus multi-process tracing, CPU-frequency transition reporting and a perf dlfilter backend that speeds trace decoding by 10–50%. Datafetcher jobs can now be compiled into Incremental computations, using a Response_or_waiting type to represent async state and mandatory memoization of fetch nodes. Quickcheck gained a [@@contract] syntax for deriving property tests from interface signatures, along with early support for bisimulation testing of two implementations of the same API.
- strace-ui, Bonsai_term, and the TUI renaissance
Jane Street Tech Blog easyNoviceJane Street's strace-ui turns strace into an interactive terminal UI with on-the-fly syscall hiding, per-file-descriptor navigation and filtering, short PID labels, hexdumped buffers, man-page lookup and hostname resolution for sockets. It is built on Bonsai_term, a terminal backend for the OCaml Bonsai framework, which models UIs as composable, incrementally computed state machines and avoids the js_of_ocaml library restrictions that complicate Bonsai_web. Text-based screenshot expect tests let coding agents run tests and read the rendered UI, a closed loop that made AI-assisted TUI development fast. Many internal terminal apps followed, including proctopus and dissect.
- Snapshot Testing For the Masses
TigerBeetle mediumAdeptA minimal snapshot testing library can be built without macros, external tools or editor integration: the core primitive is a self-updating string literal that records its source file and line (via Zig's @src()) and rewrites itself in place on mismatch. Because the snapshot is a first-class value rather than an assertion macro, it composes into helpers like diff_fmt, diff_json and domain-specific check functions, as in TigerBeetle's CLI argument parser tests. Practical details covered include opt-in updates via an env var, splicing in correctly indented string literals, tracking line shifts across multiple updates, touching the filesystem only when a test would fail anyway, CRLF pitfalls, and an <snap:ignore> marker for volatile fields like timestamps. The whole thing fits in under 500 lines.
- Bun v0.5.8
Bun mediumAdept
Bun v0.5.8 adds Jest-compatible snapshot testing to bun test via expect().toMatchSnapshot(), with --update-snapshots and a --rerun-each flag for reproducing flaky tests. A new --preload flag (or bunfig.toml preload list) runs setup files such as Bun.plugin() loaders before scripts and tests, and bun install workspaces now accept a trailing /* glob. Web API fixes bring Request/Response null-body handling, blob.slice content types and Request constructor validation in line with Chrome and Safari. Node.js compatibility work covers Buffer, os.cpus on macOS, os.networkInterfaces and AbortSignal in http, and Bun.sleepSync now takes milliseconds, a breaking change.
- The Hardest Part of Writing Tests is Getting Started
Shopify Engineering mediumAdeptGetting a test suite started is the hardest part of testing, so begin with small, incremental steps. First write a trivial test and confirm it can both pass and fail. Next test isolated functions that have no dependencies. Then use stubs and saved API-response fixtures, scrubbed of sensitive data, to isolate code from external services. Finally, add end-to-end tests: in one ETL project, stubbing the API client and testing against a real database reached over 80% code coverage, and the same approach is recommended for refactoring untested legacy code.