Prompt

How do I integrate API tests into GitLab CI?

Technology / Testing & QA1 observationLast seen Oct 6, 2026

Latest observation

Oct 6, 2026OpenAI APIWeb search: off

Here’s a practical way to integrate API tests into GitLab CI.

1) Put your API tests in the repo

Common options:

  • Postman/Newman
  • pytest + requests
  • JUnit/TestNG + REST Assured
  • pytest + Schemathesis
  • k6 / Karate / Playwright API tests

GitLab CI just needs a command that runs them.


2) Add a .gitlab-ci.yml

A basic pipeline usually has:

  • build or prepare
  • api_test
  • optional deploy

Example using pytest:

stages:
  - test

api_tests:
  stage: test
  image: python:3.12
  variables:
    API_BASE_URL: "https://staging.example.com"
  before_script:
    - pip install -r requirements.txt
  script:
    - pytest tests/api --junitxml रिपोर्ट.xml
  artifacts:
    when: always
    reports:
      junit: report.xml
    paths:
      - report.xml
    expire_in: 1 week

3) Use environment variables for endpoints/secrets

Store things like:

  • API_BASE_URL
  • API_TOKEN
  • CLIENT_ID
  • CLIENT_SECRET

In GitLab:

  • Go to Settings → CI/CD → Variables
  • Mark sensitive values as masked and protected

Then reference them in your tests:

script:
  - pytest tests/api

And in code:

import os
base_url = os.getenv("API_BASE_URL")
token = os.getenv("API_TOKEN")

4) If your API needs a service dependency, run it as a container

If you need a DB, mock server, or the app itself:

stages:
  - test

api_tests:
  stage: test
  image: python:3.12
  services:
    - name: postgres:16
      alias: db
  variables:
    POSTGRES_DB: testdb
    POSTGRES_USER: testuser
    POSTGRES_PASSWORD: testpass
  before_script:
    - pip install -r requirements.txt
  script:
    - pytest tests/api

If the API is built in the same pipeline, you may deploy it to a review/staging environment first, then run API tests against that URL.


5) Example with Newman (Postman collections)

If your API tests are in Postman:

stages:
  - test

newman_tests:
  stage: test
  image: node:20
  script:
    - npm install -g newman
    - newman run collection.json -e environment.json

You can also publish JUnit reports:

script:
  - npm install -g newman newman-reporter-junitfull
  - newman run collection.json -r junit --reporter-junit-export results.xml
artifacts:
  reports:
    junit: results.xml

6) Common best practices

  • Run API tests after deployment to a test/staging environment
  • Keep tests idempotent when possible
  • Use test data setup/teardown
  • Add timeouts and retries for flaky network-dependent tests
  • Separate:
    • smoke tests for quick validation
    • full regression tests for slower, broader coverage

You can tag jobs:

api_smoke:
  stage: test
  script:
    - pytest tests/api/smoke

7) Trigger tests only on certain branches

Example:

api_tests:
  stage: test
  script:
    - pytest tests/api
  only:
    - main
    - merge_requests

Or with rules:

api_tests:
  stage: test
  script:
    - pytest tests/api
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == "main"

8) A fuller example

stages:
  - build
  - test

build_app:
  stage: build
  image: docker:27
  script:
    - echo "Build step here"

api_tests:
  stage: test
  image: python:3.12
  variables:
    API_BASE_URL: "https://staging.example.com"
  before_script:
    - pip install -r requirements.txt
  script:
    - pytest tests/api --junitxml=report.xml
  artifacts:
    when: always
    reports:
      junit: report.xml
    paths:
      - report.xml

If you want, I can give you a ready-to-use GitLab CI file for your specific stack, like:

  • Postman/Newman
  • pytest
  • Java + Rest Assured
  • Node.js + Supertest
  • Kotlin/Karate

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.