Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Introducing Test Driven Development in PHP

My workplace consists of a lot of cowboy coders. Many of them are junior. Which coincidentally contributes to a lot of code quality issues.

I'm looking for suggestions on how to best wane my team into using TDD (we can start with Unit tests, and move into regression tests, and later more automated testing).

Ultimately, I want us to learn more quickly from our mistakes, and produce better code and breed better developers.

I'm hoping there are some practical suggestions for how to introduce TDD to a team. Specifically, what tools are best to choose in the LAMP (php) stack.

Sorry if this question is too open-ended.

like image 703
chadl Avatar asked May 16 '09 06:05

chadl


People also ask

Is the PHP community test-driven?

This post is part of a series called Test-Driven PHP. Let's admit it: the PHP community has lagged a bit, when it comes to advocating test-driven development. We know we should, but, even to this day, a sizable portion of the community does not.

How do I start TDD development in PHP?

You should learn to PHPUNIT first in order to start TDD Development. Then while making your function you should always think how function can fail and write test case in phpunit and in the end you should write code in order to pass your test.

What is test-driven development?

In other words, In TDD, we write the test first and that test drives the development of a new feature. Tests are nothing but requirement conditions that we need to test to fulfill them.

What is the best tool to generate documentation from PHP tests?

Another modern tool you should look it is Codeception. It is much simplier then PHPUnit and incorporates scenario-driven approach, which is quite useful for generating documentation from tests. Show activity on this post. Test driven development is an approach where tests are always written before code.


1 Answers

After going through this process four times now, I've found that any introduction of TDD will fail without some level of enforcement. Programmers do not want to switch style and will not write their first unit test and suddenly see the light.

You can enforce on a management level, but this is time-consuming for all involved. Some level of this is necessary at the beginning anyway, but ultimately you will need automatic enforcement. The answer to this is to introduce Continuous Integration.

I've found that a CI Server is the ultimate keystone to any TDD environment. Unless developers know that something bad will happen if they don't write the tests, you'll always have cowboys who feel it's beneath them.

like image 113
womp Avatar answered Sep 27 '22 16:09

womp