std.testing ile Doğrulamalar
expect, expectEqual ve benzerlerini kullanın.
std.testing ile Doğrulamalar, CoddyKit'te ücretsiz bir Zig Academy dersidir. Bu, 4 dersinin 2. 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.
The testing Namespace
Zig's assertion helpers live in std.testing. Pull it into a short name so each check reads cleanly inside your test blocks.
const testing = std.testing;expect for Booleans
The simplest helper is expect. It takes one boolean and fails the test when that condition is false.
try testing.expect(value > 0);Helpers Return Errors
Every testing helper returns an error on failure, so you always prefix it with try. That is what makes the test stop and report.
expectEqual for Values
To compare two values, reach for expectEqual. It checks equality and, on failure, prints both the expected and the actual value.
try testing.expectEqual(5, add(2, 3));Expected Comes First
With expectEqual the first argument is the expected value and the second is what your code produced. Order shapes the failure message.
try testing.expectEqual(42, result);Comparing Slices
Two slices are equal when their elements match, not their pointers. Use expectEqualSlices and tell it the element type.
try testing.expectEqualSlices(u8, "hi", out);Comparing Strings
For text, expectEqualStrings compares two byte slices and prints a readable diff when they differ, which is perfect for output checks.
try testing.expectEqualStrings("ok", msg);Asserting an Error
Sometimes a call should fail. Wrap it in expectError to assert it returns a specific error and not a value.
try testing.expectError(error.Bad, parse("x"));Approximate Floats
Floats rarely match exactly. Use expectApproxEqAbs with a small tolerance so tiny rounding differences do not fail your test.
try testing.expectApproxEqAbs(1.0, x, 0.001);Read the Failure Output
When an assertion fails, Zig prints the expected and actual values right in the report. That diff usually points straight at the bug.
Pick the Right Helper
Match the helper to the data: expectEqual for scalars, slice and string helpers for sequences, expectError for the failure path.
Quick Check
You need to assert that two text values are exactly equal in a test. Which helper fits best?
Recap
You learned the std.testing toolkit: expect, expectEqual, slice and string checks, plus expectError. Each one needs try in front. ✅
Sıkça Sorulan Sorular
“std.testing ile Doğrulamalar” dersi ücretsiz mi?
Evet — “std.testing ile Doğrulamalar” 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.
“std.testing ile Doğrulamalar” dersinde ne öğreneceğim?
expect, expectEqual ve benzerlerini kullanın. 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 2. dersidir.
“std.testing ile Doğrulamalar” 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