September 4, 2024
Postman は、API を効率的に作成、送信、テスト、文書化できる堅牢な API 開発環境です。GitHub Actions は、コードのテストとデプロイを自動化するように設計された CI/CD プラットフォームです。Postman を GitHub Actions と統合することで、開発ワークフローの一部として API テストをシームレスに自動化できます。
.github/workflows/postman-tests.yml
。 name: Automated Testing using Postman CLI
on:
push:
branches: [main]
jobs:
automated-api-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Postman CLI
run: |
curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh
- name: Login to Postman CLI
run: postman login --with-api-key ${{ secrets.POSTMAN_API_KEY }}
- name: Run API tests
run: |
postman collection run "[collection_id]" -e "[environment_id]"
.github/workflows/postman-tests.yml
ファイルを GitHub リポジトリに保存します。メイン
ブランチ。郵便配達員ログイン
ポストマン CLI で認証するためのコマンド[コレクション ID]
プレースホルダー (実際のコレクション ID に置き換えてください)。また、で定義された環境も使用します。 [環境 ID]
変数用のプレースホルダー (実際の環境 ID に置き換えてください)。これらの手順に従うことで、PostmanとGitHub Actionsを使用してAPIのテストを効果的に自動化し、コードの変更がデプロイ前に徹底的にテストされていることを確認できます。