Zig has it’s own syntax to write tests, using the test keyword.
test
const std = @import("std");
fn add(a: usize, b: usize) usize { return a + b; }
Tests can also appear in the same file as a pub fn main.
pub fn main
test "add" { const x = 1; const y = 2; const result = add(x, y);
try std.testing.expect(result == 3); }
Use zig test to run the tests defined.
zig test
$ zig test test.zig All 1 tests passed.
website by Mark McGranaghan and Eli Bendersky | source | license zig examples by Quinn DT | source | license