在Windows上如何运行PHPUnit测试?

3

我已经通过从pear.phpunit.de下载文件并将它们提取到C:\PHP\PEAR文件夹来手动安装PHPUnit。我已经将PEAR文件夹加入了包含路径。那么我如何运行这个测试?

class StackTest extends  PHPUnit_Framework_TestCase
{
    public function testEmpty()
    {
        $stack = array();
        $this->assertEmpty($stack);

        return $stack;
    }

    /**
     * @depends testEmpty
     */
    public function testPush(array $stack)
    {
        array_push($stack, 'foo');
        $this->assertEquals('foo', $stack[count($stack)-1]);
        $this->assertNotEmpty($stack);

        return $stack;
    }

    /**
     * @depends testPush
     */
    public function testPop(array $stack)
    {
        $this->assertEquals('foo', array_pop($stack));
        $this->assertEmpty($stack);
    }
}

在PHPUnit目录中没有可执行的命令行工具。
1个回答

5
在我的电脑上,phpunit.bat 被添加到了主 php 安装目录中。我通过调用该文件来运行测试。
phpunit NameOfMyTestWithoutPhpExtension

在包含测试的目录中。
批处理文件简单地调用主 PHP 解释器,将 phpunit 作为源文件传递并附加其他参数进行调用。如果您没有批处理文件,请尝试运行。
php "c:\PHP\PEAR\phpunit.php" NameOfMyTestWithoutPhpExtension

这是一个PHP文件。没有*.exe文件,只有一个*.bat文件,它将phpunit传递给php.exe。 - socha23
好的,这个可以运行:php "c:\PHP\PEAR\phpunit.php" NameOfMyTestWithoutPhpExtension - Richard Knop

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接