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中文網其他相關文章!