我奋力奔跑名为单个测试方法testSaveAndDrop在文件中escalation/EscalationGroupTest.php使用phpunit.我尝试了以下组合:
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
Run Code Online (Sandbox Code Playgroud)
在每种情况下,执行文件中的所有测试方法escalation/EscalationGroupTest.php.如何选择一种方法呢?
该类的名称是3.2.8 EscalationGroupTest的版本phpunit.
Ale*_*lex 396
以下命令在单个方法上运行测试:
phpunit --filter testSaveAndDrop EscalationGroupTest escalation/EscalationGroupTest.php
phpunit --filter methodName ClassName path/to/file.php
Run Code Online (Sandbox Code Playgroud)
iam*_*ist 203
我更喜欢在注释中标记测试
/**
* @group failing
* Tests the api edit form
*/
public function testEditAction()
Run Code Online (Sandbox Code Playgroud)
然后运行它
phpunit --group failing
Run Code Online (Sandbox Code Playgroud)
无需在命令行中指定完整路径,但您必须记住在提交之前删除它,而不是使代码混乱.
您还可以为单个测试指定多个组
/**
* @group failing
* @group bug2204
*/
public function testSomethingElse()
{
}
Run Code Online (Sandbox Code Playgroud)
Mah*_*alt 113
这是更通用的答案:
如果您确定方法名称是唯一的,则只能按方法名称进行筛选(这对我有用)
phpunit --filter {TestMethodName}
Run Code Online (Sandbox Code Playgroud)
但是,指定文件路径/引用也更安全
phpunit --filter {TestMethodName} {FilePath}
Run Code Online (Sandbox Code Playgroud)
例:
phpunit --filter testSaveAndDrop reference/to/escalation/EscalationGroupTest.php
Run Code Online (Sandbox Code Playgroud)
快速注意:我注意到如果我有一个名为的函数testSave,另一个名为testSaveAndDropusing command的函数phpunit --filter testSave也将运行,testSaveAndDrop并且任何其他函数都以testSave*它开头,这很奇怪!
Far*_*mov 43
以下命令将执行完全 testSaveAndDrop测试.
phpunit --filter '/::testSaveAndDrop$/' escalation/EscalationGroupTest.php
Run Code Online (Sandbox Code Playgroud)
Vin*_*was 42
vendor/bin/phpunit --filter 'Your method name'
Run Code Online (Sandbox Code Playgroud)
带有自定义方法名称的示例。
/** @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');
}
Run Code Online (Sandbox Code Playgroud)
带有 test 关键字的示例
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
Run Code Online (Sandbox Code Playgroud)
sec*_*tus 20
所以,这样的事情
phpunit --filter 'EscalationGroupTest::testSaveAndDrop' EscalationGroupTest escalation/EscalationGroupTest.php
Run Code Online (Sandbox Code Playgroud)
没有=和有'
https://phpunit.de/manual/3.7/en/textui.html
Jig*_*sar 16
通过很多方式在laravel中运行phpunit测试..
vendor/bin/phpunit --filter methodName className pathTofile.php
vendor/bin/phpunit --filter 'namespace\\directoryName\\className::methodName'
Run Code Online (Sandbox Code Playgroud)
测试单班:
vendor/bin/phpunit --filter tests/Feature/UserTest.php
vendor/bin/phpunit --filter 'Tests\\Feature\\UserTest'
vendor/bin/phpunit --filter 'UserTest'
Run Code Online (Sandbox Code Playgroud)
用于测试单一方法:
vendor/bin/phpunit --filter testExample
vendor/bin/phpunit --filter 'Tests\\Feature\\UserTest::testExample'
vendor/bin/phpunit --filter testExample UserTest tests/Feature/UserTest.php
Run Code Online (Sandbox Code Playgroud)
对于命名空间内所有类的运行测试:
vendor/bin/phpunit --filter 'Tests\\Feature'
Run Code Online (Sandbox Code Playgroud)
更多方式运行测试看到更多
小智 10
鉴于你
vendor/bin/phpunit --filter=EscalationGroupTest::testSaveAndDrop
Run Code Online (Sandbox Code Playgroud)
小智 7
你可以尝试这个我能够运行单个测试用例
phpunit tests/{testfilename}
Run Code Online (Sandbox Code Playgroud)
例如:
phpunit tests/StackoverflowTest.php
Run Code Online (Sandbox Code Playgroud)
如果您想在Laravel 5.5中运行单个测试用例,请尝试
vendor/bin/phpunit tests/Feature/{testfilename}
vendor/bin/phpunit tests/Unit/{testfilename}
Run Code Online (Sandbox Code Playgroud)
例如:
vendor/bin/phpunit tests/Feature/ContactpageTest.php
vendor/bin/phpunit tests/Unit/ContactpageTest.php
Run Code Online (Sandbox Code Playgroud)
您的测试都在运行的原因是您--filter在文件名后有标志。PHPUnit 根本不读取选项,因此正在运行所有测试用例。
从帮助屏幕:
Usage: phpunit [options] UnitTest [UnitTest.php]
phpunit [options] <directory>
Run Code Online (Sandbox Code Playgroud)
因此--filter,如@Alex 和@Ferid Mövsümov 答案中所述,将参数移到您想要的测试文件之前。并且您应该只运行您想要运行的测试。
| 归档时间: |
|
| 查看次数: |
149382 次 |
| 最近记录: |