【问题标题】:Ant build.xml phpunitAnt build.xml phpunit
【发布时间】:2012-07-31 16:05:26
【问题描述】:

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

【问题讨论】:

    标签: ant build phpunit build.xml


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      <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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-01
        相关资源
        最近更新 更多