1

我有一个 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>
4

2 回答 2

2

问题是我指定 dir="runtest" 一旦我从它工作的 Execute 行中删除它。

于 2012-08-02T16:45:47.777 回答
-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>
于 2016-08-26T11:27:24.943 回答