我正在努力使用phpunit在文件escalation/EscalationGroupTest.php中运行一个名为testSaveAndDrop的测试方法。我尝试了以下组合:
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。
在你的项目根目录中运行这个,我在laravel根目录中使用。
vendor/bin/phpunit --filter 'Your method name'
自定义方法名的示例。
/** @test //Initilize this for custom method name, without test keyword
*
* Test case For Dashboard When User Not logged In it will redirect To login page
*/
public function only_logged_in_user_see_dashboard()
{
$response = $this->get('/dashboard')
->assertRedirect('/login');
}
带有test关键字的示例
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
你可以试试这个,我能够运行单个测试用例
phpunit tests/{testfilename}
Eg:
phpunit tests/StackoverflowTest.php
如果您想在Laravel 5.5中运行单个测试用例,请尝试
vendor/bin/phpunit tests/Feature/{testfilename}
vendor/bin/phpunit tests/Unit/{testfilename}
Eg:
vendor/bin/phpunit tests/Feature/ContactpageTest.php
vendor/bin/phpunit tests/Unit/ContactpageTest.php