Skip to content
>devspeak
← glossary
level 6Testing & Reliability

Assertion

also: assertions, assert, asserts

The line in a test that checks a result is what you expected. If that check fails, the test fails.

a bit more technical

A statement in a test, such as expect(total).toBe(20), that compares an actual value with an expected one and fails the test if they differ. A test is only as strong as its assertions.

picture it

The recipe step that says "the cake should spring back when pressed". Baking is the test; the press is the assertion. Skip it and you never find out if the cake is done.

why it matters

A test with weak assertions passes no matter what. Agents sometimes check only that "something came back" instead of the actual value. Reading the assertions is the fastest way to judge a test.

what your agent might say
agent
I tightened the assertions: instead of checking the response is defined, the test now checks the status is 201 and the returned title matches.
how you might use it
you → your agent
In each test, assert the exact expected values, not just that something was returned. Show me the assertions for the refund tests.
common mistake

Assuming a passing test proves the feature works. It only proves the assertions held. If they check almost nothing, the pass means almost nothing.

builds on