Unit Testing within the NetBeans 6.7.1 UI

by jon on August 1, 2009

With Zend Studio for Eclipse 7 approaching its release date, I find myself once again comparing it to NetBeans, my previous development environment. I can safely say that I'm enjoying the code templates and intelligent PHP refactoring support. I finally feel like something in the PHP community is approaching what C# and Java developers have with ReSharper.

I even managed to get the unit testing environment to work with my Zend Framework installation with a little bash scripting. I realized that the PHPUnit test runner built into netbeans requires certain command line arguments, but because its designed to do single class tests instead of using the phpunit.xml file, I had to override it.

Here's my batchtest.sh file:

#!/usr/bin/env bash
cd ~/Sites/myproject/tests
phpunit --configuration phpunit.xml $1 $2
#phpunit $1 $2 $3

with this file, I can set either to have phpunit behave like it normally would in NetBeans (line 4), or have it read my phpunit.xml file instead.

The result is a nice little test runner that's built into my development environment:

Netbeans Configuration Options

Unit Testing UI

I'm still trying to integrate code coverage, but since I get HTML reports, I think I can handle switching to my web browser for that.

{ 7 comments… read them below or add one }

Ladislav Prskavec August 10, 2009 at 7:08 am

Do you have some advice when I use this shell script and got this message “PHPUnit (version ?.?.?) is too old …(minimum 3.3.0)…”
I have phpunit 3.3.17 :-)

jon September 1, 2009 at 9:10 pm

I think you need to use the absolute path of the version of phpunit that you want to be running.
Hope that helps!

iceangel89 September 2, 2009 at 9:31 am

ok, i get in netbeans

‘”"C:\Program’ is not recognized as an internal or external command,
operable program or batch file.

i noticed if i run “phpunit” in cmd alls well. if i try to run a test in cmd eg. “phpunit test.php” i get that but the tests still run.

joshuamc September 4, 2009 at 7:26 pm

i think i’ve seen that dto somewhere before …

jon September 5, 2009 at 4:50 pm

mmm indeed! from a unit test based off of the QuickBase API code that you posted:

http://blog.joshuamcginnis.com/2008/09/php-wrapper-for-quickbase/

jon September 5, 2009 at 4:51 pm

@iceangel89, I would check to see that your path to netbeans is properly escapes (maybe the spaces in windows need some special treatment, like in unix where you need to put a ‘\’ before them.)

iceangel89 September 10, 2009 at 3:45 am

sorry, where do i put the batch file (if i use windows i use ‘.bat’ instead? any changes i need to make in the batch file?). how do i run it? i guess its in the config options image but its v small i cant see.

what does the $xxx mean? is the 1st and last line comments?

Leave a Comment

Previous post: METAphrenie website update

Next post: NetBeans Code Template for Unit Testing