Запуск и фильтрация тестов
Используйте zig test и сужайте область запуска.
«Запуск и фильтрация тестов» — бесплатный урок Zig Academy на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Zig Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Zig Academy содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
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. ✅
Часто задаваемые вопросы
Урок «Запуск и фильтрация тестов» бесплатный?
Да — полный текст урока «Запуск и фильтрация тестов» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Zig Academy, подпишись на CoddyKit PRO. Курс Zig Academy содержит 4 уроков всего.
Чему я научусь в уроке «Запуск и фильтрация тестов»?
Используйте zig test и сужайте область запуска. Ты практикуешь Zig Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Zig Academy?
Предыдущий опыт не требуется. Zig Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 4 из 4.
Сколько времени занимает урок «Запуск и фильтрация тестов»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Zig Academy?
Да. Каждый урок Zig Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Написание блоков test
- Проверки с помощью std.testing
- Распределитель для тестирования обнаруживает утечки
- Запуск и фильтрация тестов