Skip to content

Other kinds of test

Level: 201 → 301 · working knowledge

Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The bullets below are the questions the finished page has to answer.

One line: Unit, integration and doc tests all check examples you chose; the other kinds — property, snapshot, compile-fail, fuzz and benchmark — each check something an example cannot, and each is a crate or tool rather than part of the language.

What it has to cover

For each kind: the question it answers, the tool, and a minimal example beside the unit test it complements.

Kind Checks Tool
Property a rule over generated inputs, shrunk to the smallest failure proptest ↗
Snapshot output against a reviewed, stored copy insta ↗
Compile-fail that code is rejected, with the expected error trybuild ↗, or a doc test marked compile_fail
Fuzz inputs nobody thought of, until something panics cargo-fuzz
Benchmark how long, compared with last time criterion ↗
  • When a property test finds what fifty handwritten cases did not, and what a good property looks like
  • Snapshot review as a workflow: the diff is the assertion, so accepting a snapshot without reading it removes the test
  • Compile-fail tests for an API whose safety depends on code not compiling
  • Which of these run under plain cargo test and which need their own command
  • This library's own answer key, compared: every example's .out file is a snapshot test that CI re-checks

The trap it exists for

Treating more example tests as more coverage. A hundred hand-picked inputs share the blind spots of the person who picked them; a property or a fuzzer does not.

See also

Po polsku

Testy jednostkowe, integracyjne i dokumentacyjne sprawdzają przykłady wybrane przez autora. Pozostałe rodzaje sprawdzają to, czego przykład sprawdzić nie może: testy własnościowe (property-based) — regułę dla losowo generowanych danych, testy migawkowe (snapshot) — wynik względem zatwierdzonej kopii, testy „nie kompiluje się” — że błędny kod zostanie odrzucony, fuzzing — dane, o których nikt nie pomyślał, a benchmarki — czas wykonania.

Szukaj po polsku: testy własnościowe · testy migawkowe · rust proptest tutorial · rust insta snapshot · rust trybuild compile fail