---
title: "What if writing tests was a joyful experience?"
description: "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."
url: "https://swe.quest/articles/what-if-writing-tests-was-a-joyful-experience-24be6abe32cc317e"
canonical: "https://blog.janestreet.com/the-joy-of-expect-tests/"
source: "Jane Street Tech Blog"
published: "2023-01-09"
difficulty: "medium"
kind: "Opinion"
reading_minutes: 11
tags: ["testing","functional-programming","developer-productivity"]
---

# What if writing tests was a joyful experience?

A post on [Jane Street Tech Blog](https://swe.quest/sources/jane-street.md), published 2023-01-09, 11 min read, Opinion. Original: [https://blog.janestreet.com/the-joy-of-expect-tests/](https://blog.janestreet.com/the-joy-of-expect-tests/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)
- [Functional programming](https://swe.quest/tags/functional-programming.md) (Languages)
- [Developer productivity](https://swe.quest/tags/developer-productivity.md) (Engineering practices)

## Prerequisites

- unit testing basics ([easy posts on Testing](https://swe.quest/tags/testing.md?difficulty=easy))
- OCaml syntax ([easy posts on Functional programming](https://swe.quest/tags/functional-programming.md?difficulty=easy))

## Keywords

expect tests, OCaml, Bonsai, magic-trace, ppx\_expect, S-expressions, Hardcaml, Jest

## Related posts

- [What the interns have wrought, 2022 edition](https://swe.quest/articles/what-the-interns-have-wrought-2022-edition-0f4dcf7e53f3e8d4.md): Jane Street Tech Blog · 2022-08-25 · Medium · 8 min read · Functional programming, Testing, Performance engineering, Developer tools, Engineering culture
  Three 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%.
- [strace-ui, Bonsai\_term, and the TUI renaissance](https://swe.quest/articles/strace-ui-bonsai-term-and-the-tui-renaissance-cdfbd7f00b61f5f9.md): Jane Street Tech Blog · 2026-05-26 · Easy · 9 min read · Functional programming, Developer tools, Debugging, Testing, AI for coding
  Jane 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.
- [Snapshot Testing For the Masses](https://swe.quest/articles/snapshot-testing-for-the-masses-1d23ec44f416430c.md): TigerBeetle · 2024-05-14 · Medium · 8 min read · Testing, Zig, Developer tools
  A 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.
- [Bun v0.5.8](https://swe.quest/articles/bun-v0-5-8-2656173dc4d056ee.md): Bun · 2023-03-18 · Medium · 8 min read · JavaScript, Runtimes & VMs, Testing
  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.
- [The Hardest Part of Writing Tests is Getting Started](https://swe.quest/articles/the-hardest-part-of-writing-tests-is-getting-started-1901209c01252103.md): Shopify Engineering · 2023-02-02 · Medium · 9 min read · Testing
  Getting a test suite started is the hardest part of testing, so begin with small, incremental steps.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
