Setting up and running php unit tests from Eclipse - 2 / 3

In Part I, we saw how to set up phpunit on your Windows system and run php unit tests from command line.  Let us now look at how to configure Eclipse to run phpunit.  The existing documentations are either obsolete (referring to pear-based phpunit configuration) or incomplete.

We will use Eclipse Kepler SR2 (4.3.2) as reference.  (I am unable to get it working in Eclipse Luna that released yesterday (26 June 2014) and have logged a bug).  [Updated: 7 July 2014]. It works with Eclipse Luna (4.4) as well with MakeGood 3.1.0.



Install PHP Development Tools
Install PHP Development Tools




Makegood in Eclipse marketplace
MakeGood in Eclipse Marketplace

  • Choose Windows : Preferences : PHP : PHP Executables

Configure PHP executable
Configure PHP executable


  • Add the php we had installed earlier.
  • Make sure you have PHP debuger enabled.  If you have the wamp-installed php, it comes with XDebug.  Choose XDebug.

Choose PHP installation
Choose PHP installation


  • Verify PHP : Debug settings to ensure it has taken the values defined above.

Verify debug settings
Verify Debug settings


  • Choose Windows : Preferences : MakeGood.  Ensure it shows up fine as below.

Verify MakeGood installation
Verify MakeGood installation



  • Import your php project in Eclipse.  
  • Choose Project :Properties and navigate to PHP Include Path
  • Click on Add External Source Folder...


Configure PHP Include Path
Configure PHP Include Path

Notice the message in Red in the MakeGood view - MakeGood is not configured yet. Fix...
  • Add vendor folder which contains phpunit and dependant libraries to the include path

Add vendor folder
Add vendor folder


  • Click on MageGood.  
  • Add Test Folders
  • Fill Preload Script: field by browsing to autoload.php in vendor folder and selecting it.


Configure MakeGood
Configure MakeGood


  • If you have an XML configuration file, specify that.


Specif testsuite file
Specify testsuite file

  • If these steps are followed correctly, you should see the following in the MakeGood view.  


MakeGood test report
MakeGood Test Report

MakeGood test report with failure
MakeGood Test Report with failure


  • Console tab should show output similar to what you would get running the test from command prompt.


Eclipse Console view
Eclipse Console view


  • If you don't see these, right-click on a test file and choose one of Run Tests or Run All Tests below.


Choose MakeGood run options
Choose MakeGood run options

As you will see from Makegood documentation, it can be configured to run each time a change is made to a test file.   You can also debug your tests and fix problems!

In Part 3, we will see how the tests can be scripted and ran in a continuous integration server.

Comments

  1. First of all thanks a lot for sharing this blog to us.. this blog really helpful to improve my knowledge .. thanks a lot for sharing this blog

    php training institute | best php training institute | best php training institute in chennai | php training institute in chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

Opening a safe deposit locker in SBI

Opening a Kannada Word document

Automating a cordova ios build