Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🧪 testing - Test Framework

Unit Tests, Assertions, Mocking, Coverage

50
Fonksiyon
460
Satır
12.9 KB
Boyut

🚀 Hızlı Başlangıç

içe_aktar testing

// Test suite
test.suite("Matematik Testleri", fonksiyon() yap
    test.test("Toplama işlemi", fonksiyon() yap
        test.assert_eq(2 + 2, 4)
        test.assert_eq(10 + 5, 15)
    son)
    
    test.test("Çarpma işlemi", fonksiyon() yap
        test.assert_eq(3 * 4, 12)
        test.assert_ne(5 * 5, 24)
    son)
    
    test.test("Bölme sıfıra", fonksiyon() yap
        test.assert_panic(fonksiyon() yap
            değişken x = 10 / 0
        son)
    son)
son)

// Run tests
test.çalıştır()

📚 Assertions

  • assert_eq: Eşitlik kontrolü
  • assert_ne: Eşit değil
  • assert_true/false: Boolean
  • assert_panic: Hata fırlatma
  • assert_approx: Float yaklaşık eşitlik

💡 Örnekler

Unit Test Example

içe_aktar testing, string

fonksiyon email_normalize(email: yazı) -> yazı yap
    dön string.küçük_harf(string.trim(email))
son

test.suite("Email Testleri", fonksiyon() yap
    test.test("Normal email", fonksiyon() yap
        test.assert_eq(
            email_normalize("  User@EXAMPLE.com  "),
            "user@example.com"
        )
    son)
    
    test.test("Boş email", fonksiyon() yap
        test.assert_eq(email_normalize(""), "")
    son)
son)

test.çalıştır()

← regex | logging →