如何在Windows中运行PHPUnit测试?
问题描述:
所以我通过从pear.phpunit.de下载文件并将它们解压缩到C:\ PHP \ PEAR文件夹来手动安装PHPUnit。包含路径中有PEAR文件夹。我怎样才能运行这个测试?如何在Windows中运行PHPUnit测试?
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目录中没有可执行的命令行工具。
答
在我的机器上,phpunit.bat
被添加到我的主安装目录中。我运行测试通过调用
phpunit NameOfMyTestWithoutPhpExtension
在包含测试的目录中。
批处理文件只是调用主php解释传递phpunit
作为源文件和附加其他参数到它的调用。如果您没有批处理文件,请尝试运行
php "c:\PHP\PEAR\phpunit.php" NameOfMyTestWithoutPhpExtension
c:\ PHP \ PEAR \ phpunit是什么?一个* .exe文件? –
这是一个PHP文件。没有* .exe文件,只有* .BAT其通过PHPUnit来php.exe的 – socha23
我得到错误:无法打开输入文件:C:\ PHP \ PEAR \ PHPUnit的 –