Switching from simpletest to phpUnit

NetBeans is becoming my favorite IDE for php and ruby. I’ve been used simpletest for php unit-test framework for more than one year, and I didn’t realize NetBeans support phpUnit! It’s time to switch.

I chose manual install phpUnit, download release package, extract to php folder, replace tokens in phpunit.bat (windows), hookup batch file (so called script) to NetBeans. Yeah, everything looks normal.

Swtich my old simpletest file to phpUnit, just change the require path and the base class from UnitTestCase to PHPUnit_Framework_TestCase, Shift+F6, it runs! The syntax in both test frameworks are exactly same!!

Only one problem I found so far, assertEqual() hung in NetBeans 6.8, I’m using phpUnit 3.4.9. Will try the latest once I upgrade my php version.

About code coverage, I need to download Xdebug extension for php from here: http://www.xdebug.org/find-binary.php, run php -i , paste output into textbox, the right version will be automatically picked up. Wow, what a smart community!

My php code in Netbeans is very colorful now.

Here is the install steps on Mac:

  1. Install PEAR, according to this page, get the go-pear.php file, run php go-pear.php.
  2. Install phpUnit, see instruction here, needs to manually cp phpUnit folder to default php extension folder which is /usr/lib/php, not in extension subfolder. After this, phpunit shell command should be available. The trick here is to set PATH variable in Mac, echo ‘export PATH=YOURPATHHERE:$PATH’ >> ~/.profile (from  this post.)
  3. Install xDebug php extension, same as windows, goto http://pear.php.net/manual/en/installation.getting.php, follow instructions.
  4. NetBeans IDE conventions for test cases, test  class name should call targetClassTest. File name doesn’t matter.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s