TOPIC 33/5114 MINNOT STARTED

Pre-conditions, post-conditions and invariants

Three small rules give a tester oracles for free: what must be true before an action, what must be true after it, and what must always be true.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a library loan desk. Before the desk lends a book, the book must be on the shelf. After the loan, the shelf has one book fewer and the borrower has one more. And all the time, the total number of books in the library stays the same. Three rules, and a clerk can spot a mistake at once.

Daily List is a to-do list app. A person can move a task from one list to another. Tom, the tester, wants rules that tell him the move worked, without a long script.

The first rule is the precondition: what must be true before the move. The second is the postcondition: what must be true after it. The third is an invariant, a fact that must hold at the agreed visible boundaries of each action. Tom writes all three for the move.

He then makes a , that notes a value before an action and compares it with the rule afterwards. The rules are the oracle: they say what a correct result looks like.

The picture has a limit. A library clerk sees the books. A tester must find a way to read each value, such as a count in the app or a row in a database.

(SYNTHETIC / TRAINING ONLY: Daily List and every person named in this lesson are invented.)

PLAIN WORDS · 3 in this section
precondition
something that must be true first
postcondition
what is true when a use case has ended
invariant
always the same; never changing

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB Writing what must be true before, after and at the declared invariant boundaries for an action, then reading values before and after to check.

  1. Before
  2. After
  3. Always
Three rules

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
A book must be on the shelf before a loanPrecondition
The shelf has one fewer afterwardsPostcondition
The total number of books never changesInvariant
The clerk counts before and afterBefore-and-after check

WHERE THIS PICTURE STOPS

  • A clerk sees the books. A tester must find a way to read each value.
  • A library has a few simple rules. Software may have many that interact.
  • A clerk stops a loan on sight. The synthetic safe-refusal contract protects business state; a failed caller precondition alone does not specify refusal behavior.

HOOK

Before, after, invariant boundaries.

REMEMBER IT THIS WAY

A sequence: the real steps, in order.

For any move, write three lines: before it, what must be true; after it, what must be true; always, what must stay true.

What each part of the trick stands for
In the trickWhat it stands for
BeforeThe precondition, true before the move
AfterThe postcondition, true after the move
AlwaysThe invariant, true at the agreed visible action boundaries

TELL A FRIEND

The three rules are a library desk: the book is on the shelf before, the shelf has one fewer after, and the total never changes.

OFTEN MIXED UP WITH How do you know the right answer? Test oracles. The oracle lesson asks how to judge a result. This lesson gives one source of oracles: what must be true before, after and at the declared invariant boundaries.

PRACTISE AND KEEP

Sources for this topic — 5 sources
  1. Market practice

    Design by Contract (Eiffel course notes, Trinity College Dublin) ↗ — Trinity College Dublin (mathematics course notes) · A precondition is the caller's obligation, a postcondition is the supplier's obligation, and a class invariant is a property that must hold after creation and be kept by every routine (search excerpt, page not opened)

    Per the search excerpt, Bertrand Meyer's design by contract: a precondition is the caller's obligation, a postcondition the supplier's obligation, and a class invariant is a property that must hold after creation and be kept by every routine. Practitioner guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    Design by Contract (lecture slides, University of Bern) ↗ — University of Bern (Software Composition Group) · Lecture slides on preconditions, postconditions and invariants in design by contract (search excerpt, page not opened)

    Per the search excerpt, lecture slides on preconditions, postconditions and invariants. Practitioner guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Market practice

    Using Heuristic Test Oracles (Michael Kelly) ↗ — InformIT · A heuristic oracle is a way to judge a result that can be fallible, which is how a rule of what must be true is used in practice (search excerpt, page not opened)

    Practitioner article; cite for the idea that oracles are able to be wrong heuristics that suggest a problem rather than prove one. · Checked 2026-11-06

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: article as listed on the publisher's site. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. Author attribution corrected from the author’s own bibliography https://www.michaeldkelly.com/articles, opened6 November2026. The InformIT article now redirects to its generic article index; article contents remain excerpt-only.

  4. Market practice

    The Oracle Problem in Software Testing: A Survey (Barr, Harman, McMinn, Shahbaz, Yoo) ↗ — IEEE Transactions on Software Engineering, vol. 41, no. 5, 2015, pp. 507-525 · The oracle problem is the difficulty of deciding whether a result is correct (search excerpt, page not opened)

    Open-access copy on UCL Discovery. Peer-reviewed survey; cite for the definition of the oracle problem and for the human as the last source of an oracle. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: 2015, DOI 10.1109/TSE.2014.2372785. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  5. Market practice

    Building bug-free O-O software: An Introduction to Design by Contract ↗ — Eiffel Software · Publisher material opened 6 November 2026; version and scope recorded in source registry and domain audit. Synthetic Daily List outcomes follow the stated teaching contract.

    Caller preconditions, supplier postconditions, class invariants and assertion monitoring. A failed caller precondition does not by itself promise graceful refusal. · Checked 2026-11-06

    Undated publisher introduction opened 6 November 2026. Paraphrased for teaching; no licence claim.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.