[英]How to execute all tests in PHPUnit?
我正在尝试从我的测试套件运行所有测试,但是运行命令phpunit
时PHPUnit找不到测试。 我在phpunit.xml中配置testsuite。
phpunit.xml
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit backupGlobals="true"
backupStaticAttributes="false"
bootstrap="./bootstrap.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="false"
verbose="true">
<testsuites>
<testsuite name="All Tests">
<directory suffix="*.php">.</directory>
</testsuite>
</testsuites>
</phpunit>
bootstrap.php中
<?php
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('America/Sao_Paulo');
require_once(dirname(__FILE__) . '/WebTestCase.php');
WebTestCase.php
<?php
define('TEST_BASE_URL', 'http://localhost:8080');
class WebTestCase extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp() {
$this->setBrowser('*firefox');
$this->setBrowserUrl(TEST_BASE_URL);
$this->setHost('localhost');
$this->setTimeOut(30);
}
}
TestPage.php
class TestPage extends WebTestCase
{
public function testTitle()
{
$this->open("/");
$title = $this->getTitle();
$this->assertEquals('Home', $title);
}
}
如果我运行phpunit通过文件测试, phpunit TestPage.php
,可以。
如您在文档中所读:
注意如果将PHPUnit命令行测试运行程序指向目录,它将查找* Test.php文件。
最好使用这种格式的测试类。 但是,如果这不是您的选择,则可以创建phpunit.xml
文件并将其正确设置来更改此行为:
<?xml version="1.0" encoding="utf-8" ?>
<phpunit>
<testsuite name='Name your suite'>
<directory suffix=".php">/path/to/files</directory>
</testsuite>
</phpunit>
请注意,我删除了*
。 从理论上讲,phpunit应该遍历该目录并在文件末尾使用.php
执行所有文件。
我认为,如果删除*
并设置正确的路径,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.