Friday, March 30, 2012

Unit Testing with PHPUnit

Hi All. Here I am going to discuss how to write unit tests using PHPUnit. In this post I am listing down the necessary steps  to configure your testing environment. PHPUnit is unit testing software frame work for php programming language developed by Sebastian Bergmann. It is one of the xUnit family of framework.

Set up the environment

PHPUnit should be installed using the PEAR Installer.

Upgrading PEAR


If you have version less than 1.9 it is recommended to update the PEAR channel and upgrade the PEAR.

Installing PHP Extensions

PHPUnit depends on package pear/XML_RPC2 that requires curl.


Need to install Xdebug to run the tests and generate code coverage.

Installing PHPUnit

Installing PHPUnit with all dependencies.

Installing Selenium

Selenium RC integration for PHPUnit.

You need to download Selenium Server from the http://seleniumhq.org/download/
You can download the SeleniumIDE which is Firefox plugin that does record-and-playback of interactions with the browser.

In the next post we will discuss how to write your first test case using PHPUnit. Keep your testing environment configured. :)