我正在努力运行一个名为testSaveAndDrop
的测试方法,该方法位于文件升级/EcalationGroupTest.php
中。我尝试了以下组合:
phpunit EscalationGroupTest escalation/EscalationGroupTest.php --filter=escalation/EscalationGroupTest.php::testSaveAndDrop
phpunit EscalationGroupTest escalation/EscalationGroupTest.php --filter=EscalationGroupTest.php::testSaveAndDrop
phpunit EscalationGroupTest escalation/EscalationGroupTest.php --filter=EscalationGroupTest::testSaveAndDrop
phpunit EscalationGroupTest escalation/EscalationGroupTest.php --filter=testSaveAndDrop
在每种情况下,都会执行文件escalation/EscalationGroupTest.php
中的所有测试方法。如何只选择一种方法?
该类的名称为EscalationGroupTest
,phpunit
的版本为3.2.8。
以下是更一般的答案:
如果您确定方法名是唯一的,则只能按方法名进行筛选(这适用于我)
phpunit --filter {TestMethodName}
但是,指定文件路径/引用也更安全
phpunit --filter {TestMethodName} {FilePath}
例子:
phpunit --filter testSaveAndDrop reference/to/escalation/EscalationGroupTest.php
快速提示:我注意到,如果我有一个名为testSave
的函数和另一个名为testSaveAndDrop
的函数,使用命令phpunit--filter testSave
也会运行testSaveAndDrop
和任何其他以testSave*
开头的函数,这很奇怪!!
我更喜欢在注释中将测试标记为
/**
* @group failing
* Tests the api edit form
*/
public function testEditAction()
然后用
phpunit --group failing
不需要在命令行中指定完整的路径,但是您必须记住在提交之前删除它,不要弄乱代码。
您还可以为单个测试指定多个组
/**
* @group failing
* @group bug2204
*/
public function testSomethingElse()
{
}
以下命令在单个方法上运行测试:
phpunit --filter testSaveAndDrop EscalationGroupTest escalation/EscalationGroupTest.php
phpunit --filter methodName ClassName path/to/file.php
对于新版本的phpUnit,它只是:
phpunit --filter methodName path/to/file.php
问题内容: 我奋力奔跑名为单个测试方法在文件中使用。我尝试了以下组合: 在每种情况下, 都将执行文件中的 所有 测试方法。如何只选择一种方法呢? 该类的名称为,版本为3.2.8。 问题答案: 以下命令在单个方法上运行测试: 对于新版本的phpunit,它只是:
作为一名测试人员,我希望通过使用PHPUnit来测试代码的安全性和可靠性。 目前,PHPUnit只通过了11项测试中的第一项。然后它放弃其余的测试,没有消息。 我尝试过的: 删除PHPUnit,清除我的缓存(),并重新安装PHPUnit() 确保每个测试文档字符串中都有 使用\test[a-zA-Z]\作为函数名 使用phpunit--filter[未运行的测试的名称] 将PHPUnit从v8.4
我有以下测试: 这是好的,它可以运行,但是我想知道有没有一种方法可以将它作为单元测试而不是集成测试运行,并且仍然使用@mockbean@autowired。还是我错过了什么? 我试着只保留@ExtendWith(SpringExtension.class),但我得到一个关于找不到BookServiceImpl bean的异常。 我知道如何使用MockitoExtension和@mock、@inje
我是新手。我使用Gradle1.10和Ubuntu13。 我想知道是否有任何命令只执行一个单元测试类,类似于SBT中的。
我试图使用Gradle的标志运行单个集成测试。我添加了另一个源代码集,并将测试放入其中。我有一个集成测试任务 这运行得很好,但是如果我尝试运行一个测试,它会告诉我它找不到匹配的测试。我不想每次编写一个新的集成测试时都必须运行每个集成测试。有办法做到这一点吗?
如何运行一个测试用例的一个方法来调试Gradle?我试过: 但最终会出现以下错误: test类有、等。