简体   繁体   English

如何运行所有PHPUnit测试?

[英]How do I run all my PHPUnit tests?

I have script called Script.php and tests for it in Tests/Script.php, but when I run phpunit Tests it does not execute any tests in my test file. 我有一个名为Script.php的脚本并在Tests / Script.php中对它进行测试,但是当我运行phpunit时测试它不会在我的测试文件中执行任何测试。 How do I run all my tests with phpunit? 如何使用phpunit运行所有测试?

PHPUnit 3.3.17, PHP 5.2.6-3ubuntu4.2, latest Ubuntu PHPUnit 3.3.17,PHP 5.2.6-3ubuntu4.2,最新的Ubuntu

Output: 输出:

$ phpunit Tests
PHPUnit 3.3.17 by Sebastian Bergmann.
Time: 0 seconds
OK (0 tests, 0 assertions)

And here are my script and test files: 这是我的脚本和测试文件:

Script.php script.php的

<?php  
function returnsTrue() {  
    return TRUE;  
}  
?>

Tests/Script.php 测试/ 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());
    }
}  
?>

Php test's filename must end with Test.php Php test的文件名必须以Test.php结尾

phpunit mydir will run all scripts named xxxxTest.php in directory mydir phpunit mydir将在目录mydir中运行名为xxxxTest.php所有脚本

(looks likes it's not described in the phpunit documentation) (看起来喜欢它没有在phpunit文档中描述)

I created following phpunit.xml and now atleast I can do phpunit --configuration phpunit.xml in my root directory to run the tests located in Tests/ 我创建了以下phpunit.xml ,现在至少我可以在我的根目录中执行phpunit --configuration phpunit.xml来运行位于Tests /中的测试

<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         syntaxCheck="false">
  <testsuites>
    <testsuite name="Tests">
      <directory suffix=".php">Tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

我认为forPHPUnit决定自动运行它必须遵循文件名约定:somethingTest.php。

You think they would have documented this. 你认为他们会记录这一点。 I just looked through the manual, and they say you can pass a directory, but not really how to do it. 我只是查看了手册,他们说你可以传递一个目录,但实际上并不是如何做到的。

Perhaps your class name has to match the basename (everything but the ".php") of your test scripts filename? 也许你的类名必​​须匹配测试脚本文件名的基本名称(除了“.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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM