2012-08-02 3 views
1

У меня есть ant build.xml (ниже). Я могу запустить PHPUnit штраф из командной строки следующим образом:Ant build.xml phpunit

D:> PHPUnit --verbose --testdox-HTML журналы \ today.html RunTest

Это запускает все мои PHPUnit тесты внутри папки D : \ RunTest.

Моя проблема в том, когда я бегу мой build.xml как «муравей строить» он пытается выполнить файл с именем 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, вы можете получить его где PHPUnit команда в Linux

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> 
Смежные вопросы