首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ant build.xml phpunit

Ant build.xml phpunit
EN

Stack Overflow用户
提问于 2012-08-03 00:13:23
回答 2查看 3.3K关注 0票数 1

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

D:> phpunit -- logs\today.html --testdox-html运行测试

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

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

代码语言:javascript
复制
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如下:

代码语言:javascript
复制
<!-- 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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-03 00:45:48

问题是我指定了dir="runtest“,一旦我从Execute行中删除它,它就可以工作了。

票数 2
EN

Stack Overflow用户

发布于 2016-08-26 19:27:25

代码语言:javascript
复制
<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/" -只需要你的应用程序所在的文件夹路径

代码语言:javascript
复制
        <arg line="UserTest ${basedir}/classes/tests/userTest.php" />

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

代码语言:javascript
复制
        <arg value="--configuration"/>
        <arg path="${basedir}/classes/tests/UnitTest.xml"/>

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

代码语言:javascript
复制
    </exec>

    <property name="phpunit.done" value="true"/>
</target>
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11781631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档