簡體   English   中英

Ant腳本無法在Windows中運行PHPUnit測試

[英]Ant script fails to run PHPUnit tests in Windows

我正在使用Windows環境,我已經設置了phpunit

C:/ users / kanishka / Desktop / php_unit文件夾中,我有兩個php文件

user.php的

class User {
    protected $name;

    public function getName() {
        return $this->name;
    }

    public function setName($name) {
        $this->name = $name;
    }

    public function talk() {
        return "Hello world!";
    }
}

UserTest.php

<?php
require_once "PHPUnit/Autoload.php";
require_once "User.php";

class UserTest extends PHPUnit_Framework_TestCase
{
  protected $user;

    protected function setUp() {
        $this->user = new User();
        $this->user->setName("Tom");
    }

    public function testTalk() {
        $expected = "Hello world!";
        $actual = $this->user->talk();
        $this->assertEquals($expected, $actual);
    }

    protected function tearDown() {
        unset($this->user);
    }   

}

當我輸入phpunit UnitTest UserTest.php時

Sebastian Bergmann編寫的PHPUnit 3.6.3。

時間:0秒,內存:5.75Mb

OK(1個測試,1個斷言)

現在,我正在嘗試通過ant自動運行此測試

我在C:/ users / kanishka / Desktop中有ant build.xml文件

<?xml version="1.0"?>
<project name="test" default="phpunit">

<target name="phpunit">

<exec executable="phpunit" failonerror="true">

    <arg value="php_unit/UserTest.php" />   

</exec>

</target>
</project>

我正在嘗試運行UserTest.php

但我收到此錯誤

在此處輸入圖片說明

所以ant文件無法檢測到路徑:(。請幫助我,在此先感謝

我的問題是我沒有為< exec可執行文件輸入正確的值

<?xml version="1.0"?>
<project name="test" default="phpunit2" basedir="." >

<property name="phpunit.path" location="D:\xampp\php"/>

<target name="phpunit2">
    <exec executable="${phpunit.path}/phpunit.bat" dir=".">
        <arg path="php_unit/UserTest.php" />
    </exec>
</target>

</project>

現在它正在工作:)

我從這個問題中得到了主意

Ant在Windows路徑中找不到可執行文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM