[英]How to execute all tests in PHPUnit?
I'm trying run all tests from my testsuite, but PHPUnit not found the tests when I run command phpunit
. 我正在尝试从我的测试套件运行所有测试,但是运行命令
phpunit
时PHPUnit找不到测试。 I config testsuite in phpunit.xml. 我在phpunit.xml中配置testsuite。
phpunit.xml 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 bootstrap.php中
<?php
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('America/Sao_Paulo');
require_once(dirname(__FILE__) . '/WebTestCase.php');
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 TestPage.php
class TestPage extends WebTestCase
{
public function testTitle()
{
$this->open("/");
$title = $this->getTitle();
$this->assertEquals('Home', $title);
}
}
If I run phpunit passing file test, as phpunit TestPage.php
, is ok. 如果我运行phpunit通过文件测试,
phpunit TestPage.php
,可以。
As you can read in the documentation : 如您在文档中所读:
Note If you point the PHPUnit command-line test runner to a directory it will look for *Test.php files.
注意如果将PHPUnit命令行测试运行程序指向目录,它将查找* Test.php文件。
It is good practice to have your testing classes with this format. 最好使用这种格式的测试类。 However, if that's not an option for you, you can change this behaviour creating the
phpunit.xml
file and setting it up properly: 但是,如果这不是您的选择,则可以创建
phpunit.xml
文件并将其正确设置来更改此行为:
<?xml version="1.0" encoding="utf-8" ?>
<phpunit>
<testsuite name='Name your suite'>
<directory suffix=".php">/path/to/files</directory>
</testsuite>
</phpunit>
Note that I removed the *
. 请注意,我删除了
*
。 In theory, phpunit should go through the directory and execute all files with .php
at the end of the file. 从理论上讲,phpunit应该遍历该目录并在文件末尾使用
.php
执行所有文件。
I think that if you remove the *
and set the correct path, it should work. 我认为,如果删除
*
并设置正确的路径,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.