I was doing some quite a bit research on this and eventually come up some results. BTW, I was introducing how to use ANT to batch run JUnit testing in this post.
The environment I am using is Ubuntu 12.04 server with LAMP, java JDK build 1.7.0_17-b02, apache ant 1.8.4. Before I continue this post, I assume that you know how to use ANT to run JUnit testing; otherwise, please check the previous post earlier.
Basically there are two steps involved to make it happen.
First of all, I would like to create a bash file which is going to be executed by PHP. And the bash file looks like the following.
#!/bin/bash /usr/local/apache-ant-1.8.4/bin/ant all
And make sure you update bash file’s file permission to make it executable…
Secondly, in the PHP file, I will use the following simple syntax to call the bash file.
echo "<h1>JUNIT test:</h1>"; $output = shell_exec("./do_build.sh"); //run bash file //$output = shell_exec('/usr/local/apache-ant-1.8.4/bin/ant all'); //run Ant directly without bash file echo $output;
Note that it is important to make sure PHP file and other needed folder and files are executable by the user who is running Apache server. I was having problem that I was able to run PHP file in terminal to execute bash file, BUT not able to run PHP file in browser since all PHP files are under the ownership and group of root; however, Apache server was running under www-data user by default. And if other related files are under root NOT under www-data, then web server may fail to manage related files, such as delete old build and report files.
That is it. Based on this, you can build some neat PHP applications to handle JUnit testing online.