assertion

A check that a condition is true, which stops a test or program with a failure if it is false.

In more detail

Test frameworks each provide assertion helpers, such as equal to, contains or throws, that compare an expected value with the actual one and report both when they differ. Some languages and tools also have a built-in form, such as Python's assert statement or Ansible's assert module. A test whose assertions can never fail proves nothing.

Examples

ansible.builtin.assert:
  that: result.stat.exists
Molecule verification uses assertions to prove the end state a role promises.
await expect(page.getByRole("status")).toHaveText("Ready")
JUnit: assertEquals("Hello Ada", Greeting.text("Ada"));
AssertJ: assertThat(names).containsExactly("Ada", "Lin");
assertEquals("Hello Ada", Greeting.text("Ada"));
In this course: In Python and pytest an assertion is the plain assert statement followed by an expression, such as assert total == 1000. When the expression is false, Python raises an AssertionError and pytest reports the values involved. A failed assertion ends the test immediately, so any later assertions in the same test never run.
assert charged == 1200

Related terms

Taught in

References