是否可以在setUp fixture中获得当前测试?

时间:2012-02-23 01:39:45

标签: php phpunit fixtures

我找不到任何这样的东西,我猜它不存在......

class Test extends PHPUnit_Framework_TestCase {
    public function setUp() {
        echo $current_test; // Output a string "testOne"
    }

    public function testOne() {
        // This is the first test; before this test is ran setUp() is called.
        // The question is, is there any way to know within setUp() what the 
        // current test is?
    }
}

1 个答案:

答案 0 :(得分:6)

$this->name应包含当前的测试用例方法名称。您可以使用$this->getName()访问它(正如David所指出的那样)。

https://github.com/sebastianbergmann/phpunit/blob/3.6/PHPUnit/Framework/TestCase.php查看TestCase的API。浏览属性及其评论,以了解可用的内容。