1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【CI/CD】Tavern で API 自動テスト!

Last updated at Posted at 2021-01-08

はじめに

Tavern という API テストツールがあります。
API の Request や Response を yaml で記述することが出来ます。
@os1ma さんの記事で知りました。
このツールで API 自動テストのパイプラインを構築した話を書きます。

API テスト

僕たちのチームでは、Postman を使うことが多いです。
テストコードを見やすく、実装するため、Tavern を使うことを決めました。

実装

  1. tavern を入れた Container を build する。
  2. tavern のテンプレートを実装する。
tavern-ci --stdout test.yaml --log-to-file test.log
  1. runner を用意する。
  2. GitLab から runner を起動する。

gitlab-ci の log は、こちら。

log
============================= test session starts ==============================
platform linux -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: /builds/tests
plugins: tavern-1.6.0
collected 1 item
test.tavern.yaml F                                             [100%]
=================================== FAILURES ===================================
...

============
TESTS0020 0.033
TESTS0025 0.634
TESTS0030 0.0910001
TESTS0085 0.0579998
TESTS0090 600.011
TESTS0095 86.047
TESTS0105 112.684
TESTS0110 0.0489998
TESTS0115 0.0439999
TESTS0120 11.638
TESTS0125 0.346
TESTS0141 0.0600002
TESTS0190 0.0309999
TESTS0210 0.511
TESTS0220 6.805
============
Job succeeded

まとめ

これが今回構築した自動テストのパイプラインです。

以上。

皆さんの参考になれば幸いです。

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?