PHP testing

I am a PHP web developer. I have limited experience using Test Driven Development in C # desktop applications. In this case, we used nUnit for a unit testing system.

I would like to start using TDD in new projects, but I'm really not sure where to start.

What recommendations do you have for the PHP framework and what are some good resources for those who are fairly new to the concept of TDD?

+41
php unit-testing tdd
Sep 05 '08 at 16:48
source share
7 answers

I used both PHPUnit and SimpleTest , and I found SimpleTest to be easier to use.

As for TDD, I was unlucky with him in the pure sense. I think it's mostly a matter of time / discipline on my part, though.

Adding tests after the fact was somewhat useful, but my favorite things are to use the SimpleTest tests, which check for specific errors that I have to fix. It is very simple to verify that things are really fixed and remain fixed.

+39
Sep 05 '08 at 16:54
source share

I highly recommend Kent Beck's Test-Driven Development (ISBN-10: 0321146530) . It was not written specifically for PHP, but concepts exist and should be easily translatable into PHP.

+11
08 Sep '08 at 21:18
source share

PHPUnit is the standard, but it is also sometimes overwhelming, so if you find it too complicated, check out phpt to get started. It is very, very easy to write tests. No problem for any programmer.

And to answer your TDD question - I'm not sure if TDD is used in the PHP space. I see that the rapid development of applications and TDD are somewhat contradictory (strictly IMHO). TDD requires that you have a complete picture of what you have created, and you write your tests in front, and then implement the code to pass the test.

So, for example, what we do is write a lot of tests when we are done. This is not always the best approach, because sometimes you end up with dummy tests that pass, but are not very useful, but at least this is something you can expand on. Inside we continue the tests and basically write a test for each error found. This is how it becomes more durable.

+9
Sep 05 '08 at 17:24
source share

I personally prefer SimpleTest. There is a command line test runner and web tester, and there is even an Eclipse plugin that allows you to run unit tests from the IDE itself. I found connecting Zend with PHPUnit a lot more complicated, especially for the debugger.

We use SimpleTest internally with a continuous integration script that we wrote ourselves. Every time we test the SVN function, we include unit tests. Every hour or so, the CI script runs and calls the command line PHP script, which runs all of our unit tests. If any break, I get an email. This is a great way to reduce errors on our systems.

However, you can just as easily use something like Phing to run tests automatically, either on a cron job or using the SVN Registration Key.

In fact, if you want to contact me directly for more help, you can contact me through my SO profile information. I would like to help you.

+4
Sep 05 '08 at 21:56
source share

SimpleTest is a great system. I started with it about 5 months ago, never heard of TDD, and SimpleTest is easy to learn, but still powerful. As for resources, I am now reading TDD following the example of Kent Beck, and that's good.

+2
Sep 05 '08 at 16:55
source share

You should look into PHPUnit , it is very similar to nUnit.

+1
Sep 05 '08 at 16:53
source share

Another modern tool you should look at is Codeception . It is much simpler than PHPUnit and includes a script-based approach, which is very useful for creating documentation from tests.

+1
Feb 27 2018-12-12T00:
source share



All Articles