Running PHPUnit from Eclipse on a remote system

Posted by on Oct 17, 2012 in Test Driven Development | No Comments

For the last few years I’ve been using virtual machine to keep my dev Linux isolated from my desktop. Recently I decided to improve my test driven development by integrating PHPUnit with Eclipse. I didn’t want to waste time on switching between IDE and console to run a test. The challenge is to create an external tool which will SSH into the remote server, run tests and feedback to Eclipse. In fact this method lets you do anything on the remote server, not only unit test.

1. Download openSSH
If you develop on Windows as I do the first step is to install command line SSH client (putty won’t work). Go to http://sshwindows.sourceforge.net/ and install openssh.

2. Generate SSH keys
Once that done login on your remote server and generate SSH keys. It’s required in order to automate the process – you don’t want to be prompted about password each time you run a test. In fact Eclipse doesn’t handle STDIN so you have no choice. If you want to learn more about SSH keys go to https://wiki.archlinux.org/index.php/SSH_Keys.

I leave the passphrase empty to make it easier. Copy the private key (eclipse.key) to your desktop. I keep it on G: drive.

Run your desktop console to try the key and confirm server’s finger print. Start –> Run –> cmd [enter].

Obviously the IP and the username should be change accordingly to your setup.

3. Create a batch script
Next what we need is a small batch script which will be executed by Eclipse. I called it eclipse-external.bat and put it into my project. If your path to OpenSSH is different please change it.

There is no magic here. The script executes SSH and takes 4 arguments. First one is a path to the ssh key. Second is username(at)address. Third is a bash script on the server and the last one will be a file name to be unit tested. Just because I develop on windows I need to replace all “\” in a file name with “/”.

4. Create a bash script
We need one more script. This time on the remote server.

unittest.sh:

5. Eclipse setup
All the hard work is done. Now it’s the time to put it all together in Eclipse.

Go to Run –> External Tools –> External Tools Configurations
eclipse1

eclipse2

Set location to your batch script. In the arguments window paste:

Obviously the second line needs to be changed.

${resource_path} is the active file. If you want to run a particular test make it active then run the config. If a selected file is not a test all test will be run.

Leave a Reply