2012-08-02 89 views
1

我有一個ant build.xml(如下)。我能夠在命令行中運行PHPUnit的罰款如下:Ant build.xml phpunit

d:> PHPUnit的--verbose --testdox-HTML日誌\ today.html的runTest

這將運行該文件夾d內的所有我PHPUnit測試:\ runTest方法。

我的問題是,當我跑我的build.xml爲「Ant構建」它試圖執行被稱爲runtest.php從螞蟻的輸出文件如下:

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

問題是我指定dir =「runtest」,一旦我從它的Execute行中刪除它的工作。

-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>