1
votes

I'm using Jenkins with Ant plug-in to run PHPUnit/Selenium tests. I'm trying to set up several Jenkins jobs (I've only had one job previously). Tests for these jobs are in the same GitHub repo, but different folders. So, I could create different Ant targets in my build.xml, but do I need separate phpunit.xml files for each job (and if so, how do I specify file names in Ant build script?) Or is there a way to make Ant distinguish between tests in the same phpunit.xml file? Any other good way to go about this? Any examples would be appreciated.

Ant build file:

<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="build">
<target name="build" depends="clean,prepare,phpunit"/>

 <target name="clean" description="Cleanup build artifacts">
  <delete dir="${basedir}/build"/>
 </target>

 <target name="prepare" description="Make log and coverage directories">
  <mkdir dir="${basedir}/build/logs"/>
  <mkdir dir="${basedir}/build/coverage_selenium"/>
 </target>

 <target name="phpunit" description="MyTests">
  <exec dir="${basedir}" executable="phpunit" failonerror="true"/>
 </target>

</project>

phpunit.xml:

<phpunit>
  <testsuites>
     <testsuite name="MyTests">

          <file>path/to/test.php</file>

    </testsuite>
  </testsuites>
</phpunit>

Thanks!

2
Both answers were helpful. What I ended up doing was creating separate Ant build files and phpunit.xml files for every project. Then, in Jenkins when I configured each job, under Build, I clicked "Advanced", and in "Build File" field I typed in the name of build file for this particular job. The phpunit target in Ant build file looks like this: <target name="run.tests" description="Run tests with PHPUnit"> <exec dir="${basedir}" executable="phpunit" failonerror="true"> <arg line="--configuration ${basedir}/phpunit_1.xml" /> </exec> </target>Stan Sarber

2 Answers

1
votes

You can specify the test configuration file using -c or --configuration. The Ant exec task lets you specify arguments for the process you want to run, something like:

<exec dir="${basedir}" executable="phpunit" failonerror="true">
    <arg value="-c" />
    <arg value="php_unit_1.xml"/>
<exec>
0
votes

I recommend creating a separate build.xml and phpunit.xml for each project. You can define common targets in a central build-base.xml that you include in each to avoid duplication. Unfortunately, there's no equivalent mechanism for phpunit.xml that I know of.