# Assertion

> A line in a test that says what must be true, or the test fails.

**Field:** Software Development  
**Category:** Testing & Quality  
**Also known as:** Assert, expect

## Think of it like

Think of it like a scale. You say the box weighs 5 kilos, then you weigh it.

## Definition

An assertion is a line in a test that states what must be true. If it is true, the test goes on. If it is false, the test stops and fails, and shows what it got instead. In Python it is written with assert; in JavaScript it is often expect. A test with no assertion checks nothing, even when it passes.

## Example

Emma's test asserts that the total is 6. It is really 5, so pytest prints assert 5 == 6 and marks the test failed.

## Example code

```console
$ pytest -q test_fail.py
E       assert 5 == 6
FAILED test_fail.py::test_total - assert 5 == 6
1 failed in 0.03s
```

The assertion expected 6, got 5, and the test failed.

## Why it matters

Assertions are what make a test a test. They turn running code into checking code.

## Common mistake

Writing a test that runs code but asserts nothing. It always passes and catches no bugs.

## Three principles

- **States what must be true.** The expected result.
- **False means fail.** And it shows what it got.
- **No assertion, no test.** It checks nothing.

## Related terms

- [Test Case](https://learn.benibix.com/term/development/test-case)
- [Software Testing](https://learn.benibix.com/term/development/software-testing)
- [Test Runner](https://learn.benibix.com/term/development/test-runner)
- [Boolean](https://learn.benibix.com/term/development/boolean)
- [Arrange-Act-Assert (AAA)](https://learn.benibix.com/term/development/arrange-act-assert)

---

Source: https://learn.benibix.com/term/development/assertion
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
