0
0
Postmantesting~8 mins

API versioning validation in Postman - Framework Patterns

Choose your learning style9 modes available
Framework Mode - API versioning validation
Folder Structure
Postman-API-Versioning-Validation/
├── collections/
│   ├── v1_api_tests.postman_collection.json
│   ├── v2_api_tests.postman_collection.json
│   └── shared_tests.postman_collection.json
├── environments/
│   ├── dev.postman_environment.json
│   ├── staging.postman_environment.json
│   └── prod.postman_environment.json
├── scripts/
│   ├── pre-request-scripts/
│   │   └── set-version-header.js
│   └── test-scripts/
│       └── validate-version-response.js
├── reports/
│   └── test-run-reports/
├── README.md
└── postman_globals.json
Test Framework Layers
  • Collections: Group API requests by version (v1, v2) and shared tests for common validations.
  • Environments: Define variables for base URLs, credentials, and version headers per environment (dev, staging, prod).
  • Pre-request Scripts: Scripts that set the API version header dynamically before each request.
  • Test Scripts: Scripts that validate the response includes correct version info and expected behavior.
  • Reports: Store test run results exported from Postman or Newman for analysis.
Configuration Patterns
  • Environment Variables: Use Postman environments to manage base URLs and version headers per environment.
  • Version Header Variable: Define a variable like api_version in environments to switch API versions easily.
  • Pre-request Script: Use a script to set the Accept-Version or custom version header before each request based on environment variable.
  • Credentials: Store sensitive data in environment variables, not in collections, to keep them secure and reusable.
Test Reporting and CI/CD Integration
  • Use Newman CLI to run Postman collections in CI/CD pipelines (GitHub Actions, Jenkins, GitLab CI).
  • Generate JSON or HTML reports from Newman runs for easy review.
  • Integrate test runs into build pipelines to block deployments if version validation tests fail.
  • Store reports in reports/test-run-reports/ folder for historical tracking.
Best Practices
  • Separate Collections by API Version: Keep tests for each API version isolated to avoid confusion and ease maintenance.
  • Use Environment Variables for Versioning: Avoid hardcoding version headers; use variables to switch versions quickly.
  • Validate Version in Response: Always check that the API response contains the expected version info to catch mismatches.
  • Reusable Scripts: Write common pre-request and test scripts to reduce duplication and improve consistency.
  • Secure Sensitive Data: Never hardcode credentials or tokens in collections; use environment variables with proper access control.
Self Check

Where in this folder structure would you add a new test script to validate the API version header in the response?

Answer: In the scripts/test-scripts/validate-version-response.js file, which contains test scripts for validating API responses.

Key Result
Organize Postman API versioning tests by versioned collections, environment variables for version headers, reusable scripts, and CI/CD integrated reporting.