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

vel*_*lo9 5 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?
    }
}
Run Code Online (Sandbox Code Playgroud)

Mik*_*e B 6

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

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