NetBeans IDE and Test Driven Development

While going through the Yii book I started my first practical experience with test driven development.

I am using NetBeans IDE for my php development sinds recently, but discovered it has some build in capabilities for PHP Unit, and a plugin for Selenium RC.

I got it working so that it runs the functional tests and unit tests all at once, but I cannot run just a single test.

Anyone out here wanting to do the same thing?

[font=“Arial”]Small question… when you run all the tests, do you also get “SKIPPED” as first result (and output is [/font][font=“Arial”]Fatal error: Class ‘WebTestCase’ not found in …[/font][font=“Arial”])?[/font]

[font="Arial"]Also, small suggestion (not related to your question) the Selenium PHP plugin for NetBeans is bundled with Selenium 1.0.1 and I had issues when testing with Firefox, so I downloaded the last Selenium version and replaced the selenium-server file inside the plugin folder (you have to use the same filename of the original file).[/font]

I noticed these errors with PHPUnit < 3.4.x.

I’ve read some messages about this, but I’m using 3.4.15 and I still notice that error (I already tried to re-install PHPUnit several times).

Just right click your test file and select Run(Or select your test file and press shift+F6).

Run was the function I was looking for for single files :)

Has anyone set up his project to also include Yii framework code/documentation, instead of just the generated application? I would like to have it while autocompleting functions and such…

Right click your projrct. Select Properties. Select PHP Include Path. Click Add Folder to add your yii framework folder.

Here’s an extra tip:

  • Goto: Tools/Options/Miscellaneous/Files

  • Add to the front of "Files Ignored by the IDE" the file "^(yiilite.php|CVS|SCCS|…"

  • Restart NetBeans

This way you don’t get double and undocumented code from yiilite.php in your autocomplete tooltips.

I’ve created a Cookbook page with NetBeans info:

Can anyone help me to get this working, please?

I have installed netbeans v6.8, phpunit v3.5 and netbeans’ plugin “Selenium Module for PHP” v1.0. I started with an empty webapp created by yiic, then created a new netbeans project with existing source.

Setting up the test directory was the first trouble: for some reason, I can’t do that in the project properties (text field takes no input). So I tried to generate a test case for the LoginForm model. This drives netbeans to ask for a test folder, which I set to protected/tests. The generation of the unit test fails, because PHPUnit doesn’t find the class CFormModel. But the project explorer now shows a folder “Test Files” below “Source Files”. Guess that is okay…

Now I thought it was time to check if unit testing works, so I put a dummy test for LoginForm into tests/unit:

class LoginFormTest extends CTestCase


    public function testRules()


        $loginForm = new LoginForm();

        // just wanna know if PHPUnit works

        $this->assertTrue( count($loginForm->rules()) === 3 );



When I tried to run that test, PHPUnit again complained that it didn’t know CTestCase, so I configured it to use tests/bootstrap.php as bootstrap file. Now the single test passes, but I can’t figure out how I would run all my unit tests?

Pressing <Alt> + <F6> took a while, and resulted in some errors. Something about IE could not been started (sure, I’m on Ubuntu right now) and that a connection to selenium rc could not be established. Until this point, I only wanted to do some unit testing, so I don’t know why netbeans tried to start functional tests. Maybe because of the “functional” folder within the “Test Files”? I can only guess, that netbeans tries to start every file within this folder if you just say “test”…

Okay, moving on. Trying to get functional tests working…

I reviewed WebTestCase.php (changing the TEST_BASE_URL), bootstrap.php (seems okay) and phpunit.xml (removing the browser entry for IE). I also configured PHPUnit to use the phpunit.xml file as XML configuration and disabled the bootstrap checkbox, since the xml seems to configure it already.

Single unit test still works, <Alt> + <F6> still fails. Some Details: LoginFormTest passes, SiteTest is skipped (no valid test cases found), SiteTest (Firefox) fails (could not connect to selenium rc server). So SiteTest seems to be executed twice, first as unit test, second as functional test. Not what I intended to do…

Trying to run only functional tests, I came across the problem, that the menu entry wasn’t enabled. I told netbeans to create a new “Selenium Test Case for PHP”, which again brought up a dialog that allowed me to specify a test folder. A chose protected/tests again, then canceled the dialog. Now I was able to select “Run selenium tests” from the project folder. The output was exactly the same as when I pressed <Alt> + <F6>. Still no connection to selenium rc server, plus unit tests I didn’t intend to run.

Last try: select different folders for unit testing and functional testing. Since die IDE doesn’t provide a possibility to configure these settings once they are set, I edited nbproject/ I set test.src.dir to protected/tests/unit and selenium.src.dir to protected/tests/functional. This gave me a new folder in the project explorer: Besides “Source Files” and “Test Files”, there were now a folder called “Selenium Test Files”.

Result: Single Test still worked. <Alt> + <F6> still tries to do everything (isn’t it possible to only do unit tests?!), “Run Selenium Tests” also tries to do everything. Pretty annoying. :(

I also tried to configure the selenium plugin to use chrome instead of firefox, but without luck, same result (can’t connect to selenium rc server). I’m pretty sure it is running, since I can’t start it manually from the console (downloaded it before I realized the plugin comes with its own copy). If I exit netbeans, I can start it manually.

Is there anyting I’ve missed? Something I haven’t yet though of? More configuration files that need to be ajusted? I’m really running out of ideas here…

You cannot enter anything in the text field directly, but you can use the browse button to the right. Anyways, you set up the test path correctly.

Shift-F6 is the correct hotkey for testing single files. Alt-F6 will run all tests ;)

Try updating the version of Selenium RC. A previous post in this topic suggests 1.0 has problems with Firefox.

I have never tried generating test cases from NetBeans, only created my own class files for unit testing.

I have installed netbeans v6.8,

Is there any reason for not upgrading to 6.9.1?

There’s no browse button in v6.8, seems they simply forgot it. ^^

Luckily that’s not much of a problem.

I’ve read the post about the problems with firefox, that’s why I also tried with chromium. Of course it’s possible that both browsers have the same problem, so at least I’m willing to upgrade the selenium server. The problem is, that I’ve no idea where those netbeans plugins get installed. And ekerazha mentioned, that one has to use the filename of the original file, which sounds to me as if it was something different that ‘selenium-server.jar’, so I have no clue what to search for. :unsure:

No specific reason, I simply installed it using synaptic. Now I updated to 6.9.1, and at least, there is the button that let’s me select the folder for unit tests in the settings dialog. But no luck with the functional tests till now.

Thanks for your replies! If anyone has more suggestions, please let me know.

You might want to do some changes:

0.- Rename your selenium-server.jar to selenium-server-1.0.1.jar and place it in your userdir by default it is in my widowsxp pc under C:\Documents and Settings\Bajja.ISSP_00\.netbeans\6.9\modules\ext\selenium

1.- Right click your project. Select PHPunit. Activate Use Bootstarp (and browse to you bootstarp file) and Use Bootstarp for creating New unit Tests.

2.- In WebTestCase.php change setUp:


protected function setUp()






3.- In WebTestCase.php change

define('TEST_BASE_URL','http://localhost/[b]testdrive[/b]/index-test.php/'); //testdrive => must be your application.

If this does not work, please report your errors.

:lol: It’s working now!

The problem was the outdated selenium-server (1.0.1). I found it in ~/.netbeans/6.9/modules/ext/selenium (don’t know why my search didn’t show it, maybe it doesn’t search hidden folder by default? Have to check that…), replaced it with version 1.0.3 (named as ‘selenium-server-1.0.1.jar’), restarted netbeans (just in case) and voilà!

Thanks a lot!

By the way, has anyone of you run the SiteTest generated by yiic? To me, it reports one error:


install PHPUnit on Xampp,but not working… help me

i try this … My link

You can start here:

And you have to be more clear about what steps you did and what results you get, ‘not working’ is not helping.

I figured out how to install NetBeans 7.0 with WAMP and PHPUnit. I will be posting a link soon. Was a pain but everything work as it is supposed now!

how do you do that?

im getting Fatal error: Class ‘CTestCase’ not found in netbeans