iT邦幫忙

2021 iThome 鐵人賽

DAY 5
0
Modern Web

每天一篇文章系列 第 5

05. Feature Test x HTTP Test x API Test

打開 tests/Feature 讓我們來場激烈的 http test 吧!

http test 基本盤,兩百。

public function testSomethingIsTrue()
  {
      $response = $this->get('/');
      $response->assertStatus(200);
  }

http test 之 API 基本盤,JSON 結構。

public function testSomethingIsTrue()
{
  $response = $this->get('/api/product/1');
  $response->assertStatus(200);
  $response->assertJsonStructure([
        'product' => [
            'id',
            'name',
            'price'
        ]
    ]);
}

http test 之 web 基本盤,see。

public function testSomethingIsTrue()
{
  $response = $this->get('/');
  $response->assertStatus(200);
  $this->get("/")->assertSee("login");
}

assertSee 是比較簡單的頁面測試,複雜的畫面、流程測試會在後面的 browser test 介紹。

⬇ 想看更多精彩的 Response Assertions ⬇
https://laravel.com/docs/8.x/http-tests#response-assertions


沒想到這麼快就不知道要推薦什麼了,這樣我這系列還有什麼看頭咧。
其實也不是沒東西推薦,只是沒有主題和受眾很難發想,所以歡迎留言啊。

既然團隊裡有哲學之友,就推薦一部 2020 完結的美劇吧 The Good Place
只有四季而已很快就看完了,建議不要看任何介紹 - 相信我直接看下去。


上一篇
04. Unit Test x Cart Class
下一篇
06. DB x tinker x seeder
系列文
每天一篇文章30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言