Skip to main content

Test your Contract in CI

Once you've set up Optic to run your API tests, you can set up GitHub Actions to run them on pull requests. This will give visibility to the unexpected change in the code review process.

This example shows a GitHub Action that is testing a Node.js application using Optic's CLI. It sets up the Node environment, installs the Optic CLI, sets up the API by installing its dependencies, then runs the tests with api test.

name: Run API Testson:pull_request:branches: [ main ]
jobs:build:runs-on: ubuntu-latest  steps:    - uses: actions/checkout@v2    - name: Use Node.js  uses: actions/setup-node@v2    with:    node-version: 15    - name: Install Optic CLI      run: npm install -g @useoptic/cli  - name: Install dependencies    run: npm ci  - name: Run API tests    run: api test --ci