Giter Club home page Giter Club logo

php-tdd-unit-test's Introduction

TDD Notlarım & Unit test örneği

TDD için aldığım kısa notlar ve PHP ile hazırlanmış temel unit test örnekleri.

TDD

TDD özet olarak testlerin koddan önce yazılması gerektiğini savunan bir geliştirme sürecidir.

Açılımı "Test Driven Development" olan TDD'yi Türkçeye "Test'in Yönettiği Geliştirme" olarak çevirebiliriz. TDD tekniğini geliştirdiği kabul edilen kişi Kent Beck dir. TDD ile ilgili detaylı bilgiyi Kent Beck'in "Test Driven Development By Example" kitabından bulabilirsiniz.

TDD bize temel olarak "Çıktı ile asıl olması gereken çıktı eşit olana kadar önce test et sonra kod yaz" der.

Peki neden önce test ediyoruz?

"Ortada kod yokken hatta metod/sınıf yokken, hata vereceğini bildiğim halde neden test edeyim?". Sorusu Kafanızı kurcalıyor olabilir hatta size saçma geliyor olabilir. Fakat testleri yazarken aslında yazacağımız birimin (metod/sınıf/kod parçası) mantıksal tasarımını aklımızda canlandırırız. Aslında kod parçasının yapacağı işi kodu yazarken değil henüz kodu yazmaya başlamadan tüm resmi görerek işe koyulabiliriz. Kodun mantıksal tasarımını UML gibi diagramlar kullanarakta oluşturabiliriz.Fakat unit testler kodun mantıksal tasarımını biz yazılımcılara yine kodla açıklar ve kodu kolayca sınamamıza imkan tanır.

TDD Life Cycle

TDD Life Cycle

  • 1 - Hata alacak testi yaz
  • 2 - Testleri geç
  • 3 - Kodu refaktör et
  • (Tekrarla)

Unit Test

Bir kod parçasının doğruluğu ancak birim test ile sınana bilinir.

Kod parçasına girdiler verilerek beklenen çıktının doğruluğu test edilir.

TDD'nin yoğunlaştığı test unit testtir.

kod parçası/birim ile ne kastedilir?

Kent Beck'e göre unit(birim)'den kasıt "tek bir işe odaklı"(unit of functionality) kod parçasıdır. Bu kod parçası metod,sınıf olabilir.

Unit test Terimleri

TDD Life Cycle

  • Unit - System Under : Test edilen birim

  • Depended on component (DOC) : Birimin bağımlı olduğu metod ve sınıflar

  • Test case : Tek bir test senaryosuna verilen ad

  • Test suite : Birden çok test senaryosuna verilen ad

  • Setup : Test edilecek metodun/sınıfın istediğimiz seviyeye/duruma getirilmesi (Örn: sınıfı türet, veri tabanı bağlantısını aç,fonksiyonu çağır)

  • Excercise : Test gerçekleşme aşaması

  • Verify-Assert: Beklenti ile sonucu kıyaslama aşaması

  • Teardown : Setup'da yapılan konfigurasyonları pasif hale getirme aşaması (Örn: veri tabanı bağlantısını kapat). Genelde bu aşama Entegrasyon testinde uygulanır.

Unit test'in refaktör'e etkisi

Refaktör yazılmış kodu iyileştirme düzeltme işlemleridir. Refaktör edeceğimiz birim herzaman bizim yazdığımız bir kod parçası olmayabilir veya aylar yıllar önce yazdığımız ve unuttuğumuz kod olabilir. Senaryoları hiç bilmiyor veya unutmuş olabiliriz. Unit testler bize senaryo hakkında bilgiler verir ve önceden yazılan testlerden geçerek sistemin hali hazırdaki icrasını bozmadığımızı teyit etmiş oluruz.

php-tdd-unit-test's People

Contributors

24bulut avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.