Promptles
Testing & Quality

Assertion

beginner

Definition

A statement inside a test that says 'I expect this to be true.' If the expectation is wrong, the test fails and tells you exactly what didn't match. Assertions are how a test actually checks that the code is doing what it's supposed to.

In the wild

A test for a calculator says 'I expect that 2 plus 2 equals 4.' That's the assertion. As long as the calculator returns 4, the test passes silently. If someone accidentally breaks the addition logic and it returns 5, the assertion fails and shouts about it immediately.

More from Testing & Quality