By Mark Jones
21st August 2014
Posted in PHP, Web Dev
This series will guide you through the process of using TDD (Test Driven Development) in your own projects and will consist of three articles. This first article will explain what TDD is, the positives and negatives of TDD, and finally TDD in conjunction with Laravel.
The second article will take you through the process of creating your first test which will be classed as user-interface testing. This type of test will ensure the correct things are displayed on the page and that the page redirects successfully after performing certain functionality.
TDD (Test Driven Development) is the term for a methodology which requires the programmer to write tests for their code before they even begin to write any actual code. Therefore the tests you write will always fail first time round; it is then your job to write code to make the test pass. Finally refactor the code if necessary.
TDD is an iterative process. If you follow these steps and keep repeating then you can safely say you are using test driven development:
There are quite a number of benefits of using TDD for your projects. Some of these include the following:
The only disadvantage I could think of for TDD is that it is hard to learn and get your head around the process of testing before coding anything. This can reduce your productivity up to four months after starting to use TDD. This may not be too much of an issue in a bigger company, however smaller companies with lots of deadlines may struggle initially implementing TDD.
Laravel makes using TDD much easier.
A package called PHPUnit can easily be added to your project via the composer.json file which allows you to write automated tests. We will learn how to install PHPUnit in the next tutorial in this series.
This article has explained the basics of Test Driven-Development, its advantages, disadvantages, and how we can use PHPUnit to write automated tests in your Laravel Projects.
Next time, we will install PHPUnit in Laravel and write our very first test.