doutou6803 2014-09-23 09:00
浏览 60

Ant脚本无法在Windows中运行PHPUnit测试

I am using windows environment , I have setup phpunit

in C:/users/kanishka/Desktop/php_unit folder i have two php files

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);
    }   

}

when i type phpunit UnitTest UserTest.php

PHPUnit 3.6.3 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 5.75Mb

OK (1 test, 1 assertion)

Now I am trying to run this test automatically via ant

I have ant build.xml file in C:/users/kanishka/Desktop

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

I am trying to run UserTest.php

but I am getting this error

enter image description here

so ant file can not detect the path :( . please help me, Thanks in advance

  • 写回答

1条回答 默认 最新

  • douzhang1955 2014-09-23 11:39
    关注

    my problem was i havent put the correct values for <exec executable

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

    now it is working :)

    I got the idea from this question

    Ant can't find a executable in the Windows path

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据