2009-09-12 79 views
33

我有一个名为Script.php的脚本并在Tests/Script.php中进行测试,但是当我运行phpunit测试时,它不会在我的测试文件中执行任何测试。我如何使用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) 

这里是我的脚本和测试文件:

脚本.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()); 
    } 
} 
?> 

回答

28

我创建了以下phpunit.xml,现在至少我可以做PHPUnit的--configuration phpunit.xml在我的根目录运行位于测试测试/

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

你认为他们会证明这一点。我只是查看手册,他们说你可以传递一个目录,但不知道如何去做。

也许您的类名称必须与您的测试脚本文件名的基本名称(除“.php”之外的所有内容)匹配?

8

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

+0

这种变化命名为xxxxTest.php所有脚本为我工作 – Stephanie 2014-07-31 16:41:33

-5
<?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; 
} 
47

PHP测试的文件名必须用test.php的结束

phpunit mydir将运行在mydir目录

(看起来喜欢它不是PHPUnit文档中所述)

+0

它不是必须的。如果您的测试文件以“TestCase.php”结尾,您可以指定--test-suffix“TestCase.php”,但默认情况下,当我们未在命令中指定后缀时,phpunit仅接受后缀为“Test.php”线 – kaushik 2015-01-02 02:53:27

相关问题