Nuno Maduro最近引入了针对性测试执行的Pestphp的
方法。这引发了对各种PHP测试过滤,跳过和靶向技术的探索,涵盖了Phpunit和Pest。
->only()
首先,nuno的
>
->only()
it('returns a successful response', function () { $response = $this->get('/'); $response->assertStatus(200); })->only(); it('another test', function () { // ... })->only();
phpunit使用类似的命令行选项:
pest --dirty pest --bail pest --filter 'returns a successful response' pest --retry pest --group|--exclude-group pest --todo
>请咨询害虫CLI参考,并
以获取全面选择。 蒂姆·麦克唐纳(Tim MacDonald)在Laravel News上的“加快Phpunit测试的提示”提供了进一步的见解。phpunit --filter test_the_application_returns_a_successful_response phpunit --list-groups phpunit --group api phpunit --exclude-group live
phpunit --help
测试跳过
>跳过测试对于管理不完整或损坏的测试很有价值。 害虫使用:
->todo()
跑步
it('requires a valid email')->todo();
> phpunit使用pest --todo
:
markTestIncomplete()
详细信息不完整的测试。
public function test_the_application_returns_a_successful_response(): void { $this->markTestIncomplete('it requires a valid email'); // ... }
>针对PHP/OS版本--display-incomplete
markTestAsSkipped()
显示跳过的测试。
害虫提供类似的功能:
#[RequiresPhp('8.0')] #[RequiresOperatingSystemFamily('Windows')] public function test_windows_only(): void { // ... }
--display-skipped
it('has home', function () { // })->skipOnPhp('>=8.0.0'); it('has home', function () { // })->skipOnWindows();
以上是进行单个测试,跳过测试以及其他技巧和技巧的详细内容。更多信息请关注PHP中文网其他相关文章!