Running and Filtering Tests
Use zig test and narrow the run.
Running and Filtering Tests is a free Zig Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
One Command to Test
To run the tests in a file you call the compiler in test mode. The zig test command compiles and executes every test block it finds.
zig test src/main.zigPoint It at a File
You give zig test the root source file. It pulls in tests from that file and from any file reached through @import.
Reading the Summary
After a run, Zig prints how many tests passed. A line like "All 7 tests passed" means every test block returned without an error.
When a Test Fails
On failure Zig prints the test's name, the assertion that broke, and a stack trace. The name you chose is what makes this easy to read.
Filter by Name
Run just the tests you care about with --test-filter. Only tests whose name contains the given text are executed.
zig test src/main.zig --test-filter parseWhy Filtering Helps
While fixing one feature you rerun only its tests, so feedback is fast. The --test-filter flag matches a substring of the test name.
Skip a Test on Purpose
Return the special error.SkipZigTest from a test to mark it skipped instead of failed, which is handy for not-yet-ready cases.
if (slow) return error.SkipZigTest;Skipped Counts Separately
The summary tallies skipped tests apart from passed and failed, so a skip never hides a real problem in your suite.
Test from the Build
In a real project you usually run tests through the build system instead. A configured zig build test step compiles and runs them.
zig build testTests Need No main
A file with only test blocks and no main function still works with zig test. The test runner supplies the entry point for you.
Make Testing a Habit
Because running tests is a single command, you can do it after every change. Fast feedback is what keeps a Zig codebase trustworthy.
Quick Check
You only want to run tests whose names mention the word parse. Which command does that?
Recap
You ran tests with zig test, read the summary, filtered by name, skipped with error.SkipZigTest, and learned about zig build test. ✅
Frequently asked questions
Is the “Running and Filtering Tests” lesson free?
Yes — the full text of “Running and Filtering Tests” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.
What will I learn in “Running and Filtering Tests”?
Use zig test and narrow the run. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Zig Academy?
No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Running and Filtering Tests” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Zig Academy lesson?
Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Writing test Blocks
- Assertions with std.testing
- The Testing Allocator Catches Leaks
- Running and Filtering Tests