0PricingLogin
Zig Academy · Lesson

Assertions with std.testing

expect, expectEqual, and friends.

The testing Namespace

Zig's assertion helpers live in std.testing. Pull it into a short name so each check reads cleanly inside your test blocks.

const testing = std.testing;

expect for Booleans

The simplest helper is expect. It takes one boolean and fails the test when that condition is false.

try testing.expect(value > 0);

All lessons in this course

  1. Writing test Blocks
  2. Assertions with std.testing
  3. The Testing Allocator Catches Leaks
  4. Running and Filtering Tests
← Back to Zig Academy