Tests ausführen und filtern
Verwenden Sie zig test und grenzen Sie die Ausführung ein.
Tests ausführen und filtern ist eine kostenlose Zig Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Zig Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. ✅
Häufig gestellte Fragen
Ist die Lektion „Tests ausführen und filtern“ kostenlos?
Ja — der vollständige Text von „Tests ausführen und filtern“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Zig Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Tests ausführen und filtern“?
Verwenden Sie zig test und grenzen Sie die Ausführung ein. Du übst Zig Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Zig Academy zu starten?
Keine Vorkenntnisse erforderlich. Zig Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Tests ausführen und filtern“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Zig Academy-Lektion Code schreiben und ausführen?
Ja. Jede Zig Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- test-Blöcke schreiben
- Assertions mit std.testing
- Der Testing Allocator erkennt Leaks
- Tests ausführen und filtern