3 回答

TA貢獻1799條經驗 獲得超9個贊
擴展到其他系統的功能可能會很慢并且使測試變得脆弱。盡管如此,您還是希望確保您的getText
方法按預期工作。我會做以下事情:
專門為您的方法創建一組集成測試
getText
。這些測試向服務器發出實際的 http 請求以驗證預期的行為。Web 服務器不必是外部系統。您可以使用 php 的內置網絡服務器來提供測試 url。對于使用該
getText
方法的所有其他功能,我會模擬該方法以保持測試快速。

TA貢獻1744條經驗 獲得超4個贊
要創建新的測試用例,您可以使用make:testArtisan 命令:
php artisan make:test HogeTest
然后你可以創建你的 HogeTest,考慮到你的標題是正確的
<?php
namespace Tests\Feature;
use Tests\TestCase;
class HogeTest extends TestCase
{??
? ? public function hogeExample()
? ? {
? ? ? ? $header = ["User-Agent" => $ua];
? ? ? ? $response = $this->withHeaders([
? ? ? ? ? ? $header,
? ? ? ? ])->json('POST', $url, ['username' => $user, 'password' => $password]);
? ? ? ? $response->assertStatus(200);
? ? ? // you can even dump response
? ? ? $response->dump();
? ? }
}
這是一個簡單的示例,您可以根據需要對其進行修改。
- 3 回答
- 0 關注
- 127 瀏覽
添加回答
舉報