Zend Studio and Unit Tests

I just want to share how the Zend-Studio Feature "Run as > PHP Unittest" can be used. 

1 Include PHPUnit

Zend Studio ships with PHPUnit 3.x and you can set the PHPUnit library as Include Path.

Therefore use a right click on your project and select "Include Path" > "Configure Include Path". Then select the Tab "Libraries" in the dialog window. When you click the button "Add Library" you should see the "PHPUnit 3.x" Library.

Maybe its required to build your project again. (Project > Clean)

2 Run your Tests in Zend Studio

If everything went well you should be able to open one of your Test files and see the correct Outline as well as a nice code completion for your Tests:

  • for the outline right click on the class-name in the editor and select "Open Type Hierarchy". You should see the PHPUnit classes somewhere there.
  • For autosuggestion just click in one of your testmethods and start typing "$this->" now you should see all assert* methods as suggestion.

If that works you should be able to select "Run as > PHPUnit Test" and see the testresults as well as a code coverage.



There is also a nice feature when you want to start writing a new test: you could use "New > PHP Unit TestCase" and in the dialog you can enter the name of the class you are going to test. Zend Studio will create a TestCase class with dummies for all methods in the class you are going to test.



blog comments powered by Disqus
  1. Bytesland 22.03.11 15:28

    Unit testing is a must do! Test then code, I find it addictive. I have been using PHPUnit and have the command line set to generate code coverage, metrics and test reports. In progress of integrating into a continuous build as well.