Yii 1.1: Auto TDD - How to auto-run PHPUnit



If you are lucky enough and have the privilege to develop on a Linux based environment, this little tip might boost-up your TDD process (at least the Unit Testing part). Please note, that this should work just fine with Apple computers also, but not tested!

With the following shell command you can automatically check your test results in every 15 seconds! (under protected/tests)

watch -n 15 -d phpunit unit/

My DEV screen looks something like this (Tests are running on the top-left!)

Auto TDD

Click here to zoom!

ps: of course you can change the time (in seconds) to whatever you'd like ;)

Total 3 comments

#4671 report it
thiromi at 2011/08/02 11:38am
Runs PHPUnit only if php file is modified

If you want to have your tests run only if you changed the file run this code and be happy:

watch -n 60 -d find protected/tests/unit -mmin -1 -iname '"*.php"' -exec 'phpunit --bootstrap=protected/tests/bootstrap.php {} \;'
#2574 report it
Nickerson at 2011/01/18 01:00pm
Watch on Mac

This might help you guys out if you're on a Mac. I haven't tested it but it's worth a shot.


#2416 report it
cshelton at 2010/12/27 09:32pm
Mac OS X 10.6.5

Watch command doesn't appear to be available. I'm not really a terminal expert though, but at first glance it appears that this is a no go on Mac OS X.

Leave a comment

Please to leave your comment.

Write new article
  • Written by: imehesz
  • Category: Tips
  • Yii Version: 1.1
  • Votes: +3 / -2
  • Viewed: 16,680 times
  • Created on: Dec 25, 2010
  • Last updated: never
  • Tags: PHPUnit, testing, TDD