TDD – What is Test Driven Development?
Table of Contens
Whether you develop a small project or a large project, testing the code is a must these days. If you publish your code without testing, you might not get a problem straight away, but the worst problems are the ones you overlooked. With TDD (Test-driven Development) the probability of a potential/future problem is prevented.
What is TDD, Test-driven Development?
In a nutshell: With Test-driven development the tests are created before codes. The code is developed step-by-step based on these tests. This avoids unnecessary codes/functions/classes.
TDD by Kent Beck
The Unit Tests and units (codes) are always developed in parallel. The actual programming takes place in small, repeated micro-iterations. Such an iteration, which should only last a few minutes, has three main parts, which are called the Red, Green, Refactoring.
Red : Write a test that should check a new behavior to be programmed (functionality). You start with the simplest example. This test is initially not fulfilled by the existing program code, so it must fail.
Green : Change the program code with as little effort as possible and add to it until it passes all tests.
Then clean up the code (Refactoring): Remove repetitions (code duplication), abstract where necessary, align it according to the binding code conventions, etc. After each change, the tests are carried out and failing is prohibited to adopt the apparently incorrect change in the code used. The aim of the cleanup is to make the code simple and understandable.
Stub objects
The stub objects are the test dummies (external files, Json, XML etc.) For example, if a class needs the customer data from an external interface (other class, database, external app), you can use stub objects to simulate these data.
Mock objects
The mock objects are the internal codes. So that the project works independently of external interfaces in the local environment, the existing codes that communicate with external interfaces are simulated with their own test codes.
Advantages of test-driven development
- no untested code, so you can sleep peacefully 🙂
- clean code architecture by TDD
- no redundancies due to refactoring
Test-driven development mostly focuses on unit testing. There are other types of testing as well as Behavior Driven Development . But the basic idea of all testing concepts is testing 🙂
In the next article I will create a unit test and an acceptance test with Codeception . Until then…
Looking for a WordPress Developer?
I'm a Fullstack PHP Developer a Hosting Company in Zürich/Switzerland. I love WordPress! For personal and business purposes i use WordPress.
If you have any Problem with your WordPress Website or you want to create one do not hesitate to contact me!
Recent Comments
Recent Posts
- Fatal error: Allowed memory size of bytes exhaustedJanuary 9, 2024If you are facing the Error “Fatal error: […]
- Install FOSSBilling with DDEV (Docker + Apple Silicon)November 14, 2023I love Virtualisation. It is the perfect way to work […]
- WordPress Custom Product Loop (woocommerce_product_query)September 19, 2023If you want to loop the woocommerce products with your […]
- WordPress get Tag Cloud by ShortcodeSeptember 13, 2023I was creating a WordPress Website and i needed use […]
- WordPress Non-zero exit status returned by script [Solution]December 7, 2022You are either installing a new WordPress Website or […]
Comments
Leave a Comment