liveBook · Manning

Assertion

A software assertion is an executable check of an expected condition or property that signals failure when the check does not hold.

How 15 Manning books explain it

Build Python Web Apps with Streamlit

An assertion is a test check that evaluates an expected condition and reports a failure when the condition is false.

How it is used
Checks expected behavior and results in backend unit tests and Streamlit frontend tests.
How deep it goes
Defines a passing condition and works through result, mock-call, and UI checks without examining Python assertion internals.
Examples
Uses arithmetic checks, mocked movie-search responses, sidebar controls, session state, and result expanders.
What you can do after
Apply it via pytest and AppTest to verify expected values, API calls, and app state, then identify failed checks.

Read how Build Python Web Apps with Streamlit explains assertion →

Modern C

assert is a C standard library macro that evaluates a runtime condition and reports a diagnostic followed by abnormal termination when the condition is false.

How it is used
Checks function preconditions and other runtime properties expected to hold, especially while debugging.
How deep it goes
Explains when expressions are evaluated, what happens on failure, and how NDEBUG disables checks; does not detail macro implementation.
Examples
Uses greatest-common-divisor functions that assert nonzero inputs and the recursive helper’s argument order.
What you can do after
Diagnose/debug with assertions to expose false runtime assumptions, and configure NDEBUG to disable them in production compilations.

Read how Modern C explains assertion →

Unit Testing Principles, Practices, and Patterns

An assertion is a test statement that checks whether an observed result matches an expected condition.

How it is used
Uses assertions to verify observable outcomes instead of treating executed code or coverage as evidence of correctness.
How deep it goes
Explains explicit and implicit outcomes, then stops short of prescribing a complete assertion design method.
Examples
Uses IsStringLong, Parse, a recorded property, and an assertion-free test to contrast verification with execution.
What you can do after
Diagnose tests that execute code without verifying all relevant outcomes.

Read how Unit Testing Principles, Practices, and Patterns explains assertion →

The Art of Unit Testing 3e

An assertion is a test condition that verifies whether an actual result or behavior satisfies an expected truth condition.

How it is used
Verifies expected behavior in unit tests while making failures meaningful and readable.
How deep it goes
Explains assertion placement, failure behavior, multiple concerns, and overspecification without detailing framework internals.
Examples
Uses Jest expectations for no-throw behavior, callbacks and sums, person objects, password-verifier results, and string messages.
What you can do after
Apply it to write focused, maintainable checks that expose the behavior that actually failed.

Read how The Art of Unit Testing 3e explains assertion →

Modern C, Third Edition

assert is a C standard-library assertion macro that evaluates a runtime condition and calls abort when the condition is false.

How it is used
Uses runtime assertions to expose violated assumptions and function preconditions during execution.
How deep it goes
Explains evaluation, diagnostics, abort, and NDEBUG disabling, but stops short of implementation details for the macro itself.
Examples
Uses gcd2 precondition checks and the diagnostic produced when an assertion fails.
What you can do after
Diagnose debugging-time violations of runtime assumptions and make function preconditions explicit.

Read how Modern C, Third Edition explains assertion →

Build Financial Software with Generative AI (From Scratch)

An assert statement checks that a condition is true during program execution and signals an assertion failure when it is false.

How it is used
Validates parser results and API behavior in unit, BDD, and Locust load tests.
How deep it goes
Demonstrates equality, membership, and HTTP-status assertions with diagnostic messages, without detailing assertion runtime internals.
Examples
Uses a parsed ACH file header, file-list and credit-total scenarios, and Locust requests to /files endpoints.
What you can do after
Diagnose/debug with assertions by exposing incorrect parser output, response fields, methods, redirects, and status-code expectations.

Read how Build Financial Software with Generative AI (From Scratch) explains assertion →

100 Java Mistakes and How to Avoid Them

An assert statement is a Java language statement that evaluates a boolean condition and raises an assertion failure when the condition is false and assertions are enabled.

How it is used
Uses assertions to check invariants early during testing or staging and locate unexpected program states near their causes.
How deep it goes
Explains syntax, JVM enablement, side effects, preconditions, and analysis limits, but stops short of broader assertion design.
Examples
Uses set mutation, matcher processing, prefix normalization, and collection removal to expose assertion misuse and safer alternatives.
What you can do after
Apply assertions safely by separating side effects, enabling them in tests, and replacing failed preconditions with explicit validation.

Read how 100 Java Mistakes and How to Avoid Them explains assertion →

Web Components in Action

How it is used
Uses assertions as the checking component of a testing setup, alongside test organization and browser automation.
How deep it goes
Defines assertions and illustrates expected-value checks, stopping short of explaining assertion-library internals.
Examples
Illustrates arithmetic, a number-doubling function, and slider component values and display state.
What you can do after
Apply Chai assertions to check function results and component state.

Read how Web Components in Action explains assertion →

Effective Platform Engineering

An assertion is a declarative statement that evaluates as true or false for given data.

How it is used
Applies declarative assertions to policy-as-code decisions about whether supplied data is approved.
How deep it goes
Defines predicates, extensions, data domains, and subject variables, then connects them to true-or-false evaluation.
Examples
Uses book-writing predicates, employee lists, age-based Rego rules, and allow-or-deny policy results.
What you can do after
Evaluate policy inputs by identifying predicates, assigning subject variables, and checking whether assertions hold.

Read how Effective Platform Engineering explains assertion →

ASP.NET Core in Action, 3e

An assertion is a test operation that verifies an actual result satisfies an expected condition.

How it is used
Uses assertions to verify unit-test outcomes and expected exception behavior.
How deep it goes
Explains value and exception assertions with runnable examples, but defers broader ASP.NET Core testing.
Examples
Demonstrates currency conversion, mismatched expected values, multiple InlineData cases, and zero-rate exceptions.
What you can do after
Apply it via xUnit to verify returned values, repeated input cases, and exceptions raised by a method.

Read how ASP.NET Core in Action, 3e explains assertion →

Refactoring to Rust

An assertion is a program check that verifies a condition and reports failure when the condition is false.

How it is used
Uses assertions to verify expected values and conditions, especially within automated Rust tests.
How deep it goes
Explains Boolean and equality checks, panic behavior, failure output, and debugging values without covering assertion implementation internals.
Examples
Demonstrates 2 + 2 assertions, a deliberately failing equality check, and Cargo test failure output.
What you can do after
Apply assertions in Rust tests to validate conditions and inspect reported values when checks fail.

Read how Refactoring to Rust explains assertion →

Practices of the Python Pro

How it is used
Uses assertions as checkpoints for comparing expected and actual values in functional tests.
How deep it goes
Explains Boolean conditions, silent success, AssertionError failure, and testing-tool usage without descending into implementation internals.
Examples
Demonstrates calculate_mean checks, Product SKU tests, ShoppingCart outcomes, dictionary comparisons, and pytest test-run output.
What you can do after
Apply raw assertions in Python tests and migrate unittest comparisons to concise pytest expressions.

Read how Practices of the Python Pro explains assertion →

Learn Rust in a Month of Lunches

How it is used
Flags logic bugs by panicking when an expected condition or value comparison fails.
How deep it goes
Defines three assertion macros and demonstrates passing checks, custom failure messages, and panic output.
Examples
Checks a vector's expected length and compares a name with expected and disallowed values.
What you can do after
Apply Rust's assertion macros to check conditions and equality or inequality in code.

Read how Learn Rust in a Month of Lunches explains assertion →

Software Design for Python Programmers

An assert statement evaluates a condition and aborts execution when the condition is false.

How it is used
Enforces preconditions when continuing after invalid input could corrupt object state or return an invalid value.
How deep it goes
Defines the check and its aborting behavior, while deferring exception handling as an alternative contract.
Examples
Uses an empty CircularBuffer and an unchecked remove() call to demonstrate assertion failure.
What you can do after
Diagnose/debug with it: detect violated preconditions immediately instead of allowing invalid state to propagate.

Read how Software Design for Python Programmers explains assertion →

Python How-To

How it is used
Checks conditions before execution continues and verifies expected outputs when testing functions.
How deep it goes
Explains condition outcomes and demonstrates equality checks for a function result.
Examples
Uses f-string output comparisons and a task-creation function compared with an expected Task instance.
What you can do after
Apply it via Python's assert statement to check conditions and compare a function's result with an expected value.

Read how Python How-To explains assertion →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.