gpt4 book ai didi

zend-framework - PHPUnit:如何从浏览器运行测试?

转载 作者:行者123 更新时间:2023-12-05 01:08:06 24 4
gpt4 key购买 nike

我知道 PHPUnit 测试可以从命令行执行,但是有没有一种简单的方法可以从浏览器运行它。例如,我有:

class testsSuite extends PHPUnit_Framework_TestSuite
{

public function __construct ()
{
$this->setName('testsSuite');
$this->addTestSuite('MyFirstTest');
}

public static function suite ()
{
return new self();
}
}

然后我有:
class MyFirstTest extends PHPUnit_Framework_TestCase
{

protected function setUp ()
{
parent::setUp();
}

protected function tearDown ()
{
parent::tearDown();
}

public function __construct ()
{

}

public function test__construct ()
{

}

public function test__destruct () {

}

public function testCalculateCost ()
{
print 1; die();
}

}

是否有可以在浏览器中输入的 URL 来执行此测试?就像是:
http://localhost/tests/testsSuite/calculateCost

或者类似的东西

最佳答案

VisualPHPUnit .

在工作中,我们有时从浏览器运行,使用基本形式的 php 脚本,其中包含:

$argv = array(
'--configuration', 'phpunit.xml',
'./unit',
);
$_SERVER['argv'] = $argv;


PHPUnit_TextUI_Command::main(false);

因此,您基本上将通常在命令行上键入的所有参数放在一个数组中,并将其设置在 $_SERVER-global 中。 PHPUnit_TextUI_Cmmand::main(false);然后运行你的测试。 false 参数确保没有调用 exit() 。
在 PHPUnit.xml 中,我配置为记录到 JSON 文件,php-script 读取该文件以显示结果(它可以在测试后执行,因为没有调用退出)。

注意:这是非常准系统的,简单粗暴的。

关于zend-framework - PHPUnit:如何从浏览器运行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17608822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com