我有一个蚂蚁build.xml (下图)。我可以从命令行运行phpunit fine,如下所示:
D:> phpunit -- logs\today.html --testdox-html运行测试
这将运行d:\runtest文件夹中的所有phpunit测试。
我的问题是,当我以'ant build.xml‘运行我的构建时,它试图执行一个名为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>发布于 2012-08-03 00:45:48
问题是我指定了dir="runtest“,一旦我从Execute行中删除它,它就可以工作了。
发布于 2016-08-26 19:27:25
<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/" -只需要你的应用程序所在的文件夹路径
<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"/>xml - path="${basedir}/classes/tests/UnitTest.xml"文件的路径
</exec>
<property name="phpunit.done" value="true"/>
</target>https://stackoverflow.com/questions/11781631
复制相似问题