Ant build.xml phpunit

时间:2012-08-02 16:13:23

标签: ant build phpunit build.xml

我有一个ant build.xml(下面)。我可以从命令行运行phpunit,如下所示:

d产品:> phpunit --verbose --testdox -html logs \ today.html runtest

这将在文件夹d:\ runtest中运行我所有的phpunit测试。

我的问题是当我将build.xml作为'ant build'运行时,它试图执行一个名为runtest.php的文件,ant的输出如下:

D:\>ant build
Buildfile: D:\build.xml

check_os:

if_windows:

if_unix:

prepare:

phpunit:
     [exec] PHPUnit 3.6.11 by Sebastian Bergmann.
     [exec]
     [exec] Cannot open file "runtest.php".

BUILD FAILED
D:\build.xml:48: exec returned: 1

Total time: 2 seconds

我的Build.xml如下:

<!-- This project launches the test generator and execute all phpunit selenium tests -->
<project name="proj" default="build" basedir="">
<!--Get environment variables -->
<property environment="env" />
<property name="logFolder" value="${basedir}\logs"/>
<property name="testFolder" value="${basedir}\runtest"/>

<property name="test" value="**" />
<condition property="pattern" value="runtest/*.php">
<os family="windows" />
</condition>

<tstamp/>

<!-- Check Operating system to set phpunit path-->
<target name="check_os">
<condition property="isWindows">
<os family="windows" />
</condition>
<condition property="isLinux">
<os family="unix" />
</condition>
</target>

<target name="if_windows" depends="check_os" if="isWindows">
<property name="exe.phpunit" value="C:\\Program Files\\PHP\\phpunit.bat"/>
</target>

<target name="if_unix" depends="check_os" if="isLinux">
<property name="exe.phpunit" value="${env.PHP_HOME}/includes/PHPUnit-3.2.0/PHPUnit" />
</target>

<target name="prepare" depends="if_windows, if_unix">
<mkdir dir="${logFolder}"/>
</target>

<target name="phpunit">
<!-- Check if folder empty -->
<fileset id="fileset.test" dir="${testFolder}">
<include name="*.*"/>
</fileset>
<fail message="Files not found">
<condition>
<resourcecount refid="fileset.test" when="less" count="1"></resourcecount>
</condition>
</fail>
<!-- Execute phpunit tests -->
<exec executable="${exe.phpunit}" failonerror="true" dir="runtest">
<arg line="--verbose --testdox-html '${logFolder}\phpunit-report-${TODAY}.html' runtest" />
</exec>
</target>

<target name="build" depends="prepare,phpunit"/>
</project>

2 个答案:

答案 0 :(得分:2)

问题是我指定dir =“runtest”一旦我从它运行的执行行中删除了它。

答案 1 :(得分:-1)

<target name="phpunit" unless="phpunit.done" depends="prepare"  description="Run unit tests with PHPUnit">
    <exec executable="${phpunit}" failonerror="true"  dir="${basedir}/classes/tests/" resultproperty="result.phpunit">

${phpunit} - 需要安装phpunit的路径,你可以从linux中的phpunit命令获取它

dir="${basedir}/classes/tests/" - 只需要存在php应用程序的文件夹路径

        <arg line="UserTest ${basedir}/classes/tests/userTest.php" />

line="UserTest ${basedir}/classes/tests/userTest.php" - 这里UserTest是类名,${basedir}/classes/tests/userTest.php是测试类文件的路径

        <arg value="--configuration"/>
        <arg path="${basedir}/classes/tests/UnitTest.xml"/>

path="${basedir}/classes/tests/UnitTest.xml" - xml文件的路径

    </exec>

    <property name="phpunit.done" value="true"/>
</target>