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
只有四季而已很快就看完了,建议不要看任何介绍 - 相信我直接看下去。


<<:  NNI执行的流程

>>:  【Day 05】从零开始的 Line Chatbot-公开 APP 网址

RxJS 条件/布林类型 Operators (1) - isEmpty / defaultIfEmpty / find / finxIndex / every

今天介绍「条件/布林类型」的 operators,这类型的 operators 都是用来判断整个 O...

[Day14]PHP Class 类别01

class类 class基本概念 每个类的定义都以关键字 class 开头,後面跟着类的名,再一个括...

LeetCode解题 Day27

929. Unique Email Addresses https://leetcode.com/p...

DAY 9- 《区块密码2》AES(1)- 加密过程

"AES, ACE, ASS, AIDS(喂)" --- 现今最广泛使用的对称式...

JS Library 学习笔记:首先当然来试试 jQuery (一)

要撰写前端功能,直接使用JavaScript是绝对可行的,但要更有效率、具有良好开发体验的话,使用L...