获取在 `setUp` 中执行的测试 [英] Getting the test that is executing in `setUp`

查看:54
本文介绍了获取在 `setUp` 中执行的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在PHPUnit<中的setUp()中获取即将执行的测试(实际的函数名称)?

Is there a way to get the test that is about to be executed (the actual Function name) inside setUp() in PHPUnit?

我知道我可以将代码放在测试函数本身而不是 setUp() 中,但是我已经创建了一些 抽象 测试用例,并且自从 setUp() 执行需要很长时间,我希望能够跳过 setUp() 中不必要的操作甚至测试.

I know that I can put the code inside the test function itself instead of setUp(), but I have created some Abstract Test Cases and since setUp() takes a long time to execute, I want to be able skip unnecessary actions or even tests inside setUp().

推荐答案

您可以使用 getName 方法返回测试用例的名称(被调用的函数).如果您将 true 作为参数传递,它将返回数据集的名称(在 dataprovider 的情况下).所以只需使用:

You can use the getName method that return the name of the test case (the function that is been called). If you pass true as arguments it will return the name of the dataset (in case of dataprovider). So simply use:

public function setUp()
{
    var_dump($this->getName(false) );  // The name of the method without dataprovider

    var_dump(get_called_class()); // The name of the TestCase Class
}

希望对您有帮助

这篇关于获取在 `setUp` 中执行的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆