0PricingLogin
Zig Academy · Lesson

Writing test Blocks

Tests live right next to your code.

Tests Live in Your Code

In Zig you do not need a separate test file. A test block sits right beside the code it checks, in the very same source file.

The test Keyword

You start a test with the test keyword, a name in quotes, and a block. The compiler collects every one of these for you.

test "adds two numbers" {
    // checks go here
}

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