1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

REST APIのテスト自動化:テストサンプル

Posted at

はじめに

APIテストを書く時に使用頻度の高いサンプルコードを集めてみました。
まずはこれらの簡単なテストの実施を導入し、理解度を深めてケースを増やしていくと良い。
とりあえず稼働させてみる!
そして品質としても最低限保証すること思います!

疎通確認 ステータスチェック

pm.test("疎通を確認", function () {
    pm.response.to.be.ok;
    pm.response.to.have.status(200);
});

レスポンス速度確認

pm.test("レスポンス時間を確認", function () {
    pm.expect(pm.response.responseTime).to.be.below(3000);
});

レスポンスの値チェック

// レスポンスBody aaaaaのキーにiiiiiであることを確認
pm.test("Body aaaaaのキーを確認", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.aaaaa).to.eql(iiiii);
});

レスポンスの値をenvironmentに保存

// レスポンスのJSONデータを取得
var responseBody = pm.response.json();
// aaaaa要素の値を取得
var iiiii = responseBody.aaaaa;
// 環境変数uuuuuに値iiiiiを格納
pm.environment.set("uuuuu", iiiii);
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?