我刚刚通过Composer安装了Sebastian Bergmann的PHPUnit版本3.7.19,并编写了一个我想进行单元测试的课程.
我想让我的所有课程自动加载到每个单元测试中,而不必使用include
或require
在我的测试的顶部,但这证明是困难的!
这是我的目录结构的样子(尾部/斜杠表示目录,而不是文件):
我的composer.json文件包括以下内容:
"require": {
"phpunit/phpunit": "3.7.*",
"phpunit/phpunit-selenium": ">=1.2"
}
Run Code Online (Sandbox Code Playgroud)
我的returns.php类文件包括以下内容:
<?php
class Returning {
public $var;
function __construct(){
$this->var = 1;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我的returnsTest.php测试文件包括以下内容:
<?php
class ReturningTest extends PHPUnit_Framework_TestCase
{
protected $obj = null;
protected function setUp()
{
$this->obj = new Returning;
}
public function testExample()
{
$this->assertEquals(1, $this->obj->var); …
Run Code Online (Sandbox Code Playgroud)