如何运行所有PHPUnit测试?
-
06-07-2019 - |
题
我有一个名为Script.php的脚本,并在Tests / Script.php中对其进行测试,但是当我运行phpunit测试时,它不会在我的测试文件中执行任何测试。如何使用phpunit运行我的所有测试?
PHPUnit 3.3.17,PHP 5.2.6-3ubuntu4.2,最新的Ubuntu
<强>输出:强>
$ phpunit Tests
PHPUnit 3.3.17 by Sebastian Bergmann.
Time: 0 seconds
OK (0 tests, 0 assertions)
这是我的脚本和测试文件:
<强>的script.php 强>
<?php
function returnsTrue() {
return TRUE;
}
?>
<强>测试/ script.php的强>
<?php
require_once 'PHPUnit/Framework.php';
require_once 'Script.php'
class TestingOne extends PHPUnit_Framework_TestCase
{
public function testTrue()
{
$this->assertEquals(TRUE, returnsTrue());
}
public function testFalse()
{
$this->assertEquals(FALSE, returnsTrue());
}
}
class TestingTwo extends PHPUnit_Framework_TestCase
{
public function testTrue()
{
$this->assertEquals(TRUE, returnsTrue());
}
public function testFalse()
{
$this->assertEquals(FALSE, returnsTrue());
}
}
?>
解决方案 2
我创建了以下 phpunit.xml ,现在至少我可以在我的根目录中执行 phpunit --configuration phpunit.xml 来运行位于Tests /中的测试/ p>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Tests">
<directory suffix=".php">Tests</directory>
</testsuite>
</testsuites>
</phpunit>
其他提示
Php test的文件名必须以Test.php结尾
phpunit mydir
将在目录mydir中运行名为 xxxxTest.php
的所有脚本
(看起来好像没有在phpunit文档中描述)
我认为forPHPUnit决定自动运行它必须遵循文件名约定:somethingTest.php。
你认为他们会记录这一点。我只是查看了手册,他们说你可以传递一个目录,但不是真的如何去做。
也许您的类名必须与测试脚本文件名的基本名称(除了“.php”之外的所有内容)相匹配?
<?php
//Files required for phpunit test
require_once 'PHPUnit/Framework.php';
//Knowing the drupal environment
require_once './includes/bootstrap.inc'; //initialize the Drupal framework
//Loading the drupal bootstrap
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//Helper file
include_once 'helper.inc';
//Including inc file of addresses module
include_once(module_load_include('inc','addresses_user','addresses_user'));
class addresses_test extends PHPUnit_Framework_TestCase {
protected $uid;
protected function setUp()
{
$this->uid = 1;
}
不隶属于 StackOverflow