test Blokları Yazma
Testler kodunuzun hemen yanında bulunur.
test Blokları Yazma, CoddyKit'te ücretsiz bir Zig Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Zig Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Zig Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
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
}Name Your Tests Clearly
The string after test is its name. A clear name like "parses empty input" shows up in the report and tells you what failed.
test "parses empty input" {}Import std to Assert
Most tests need helpers, so you bring in the standard library at the top with an @import call and use std.testing inside.
const std = @import("std");A First Real Test
Inside the block you compute something and check it. Here expect passes only when the boolean condition is true.
test "two plus two" {
try std.testing.expect(2 + 2 == 4);
}Tests Can Fail
Assertion helpers return an error when the check is false. That is why you write try before them, letting the failure end the test.
try std.testing.expect(1 == 2);Test a Function You Wrote
A test usually calls one of your own functions and checks its result. The function and the test can share the same file.
fn add(a: i32, b: i32) i32 {
return a + b;
}Checking the Result
Now exercise that function from a test and confirm the output is what you expect with a single expect call.
test "add works" {
try std.testing.expect(add(2, 3) == 5);
}Many Tests, One File
You can stack as many test blocks as you like. Each runs in isolation, so a failure in one does not block the others.
Tests Are Compiled Code
A test block is normal Zig, fully type-checked. If it does not compile, the test run stops before anything even executes.
Why Inline Tests Help
Keeping checks next to the code means tests evolve with it. When you change a function, its test is right there to update.
Quick Check
You want to declare a unit test in a Zig source file. What is the right shape?
Recap
You met the test block: named, inline, fully compiled Zig that you assert with try. Tests live right next to the code they protect. ✅
Sıkça Sorulan Sorular
“test Blokları Yazma” dersi ücretsiz mi?
Evet — “test Blokları Yazma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Zig Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Zig Academy kursu toplamda 4 dersten oluşur.
“test Blokları Yazma” dersinde ne öğreneceğim?
Testler kodunuzun hemen yanında bulunur. Zig Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Zig Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Zig Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.
“test Blokları Yazma” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Zig Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Zig Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- test Blokları Yazma
- std.testing ile Doğrulamalar
- Testing Allocator Bellek Sızıntılarını Yakalar
- Testleri Çalıştırma ve Filtreleme