Generation

Contract Test

Contract Testing

This guide explains how to generate contract tests using the Skyramp CLI. Throughout this guide, we will demonstrate key capabilities using Skyramp’s Demo Shop API, a simple e-commerce API for product and order management. Learn more about the Demo Shop API.

If you haven’t already installed Skyramp, please refer to the instructions in the Installation Guide.

Overview

A contract test asserts that inter-application messages conform to a shared understanding that is documented in an API contract. In this context, every contract is between a client (consumer) and a server (provider). The consumer side is interested in making sure that the client can handle an expected response correctly. The provider side is interested in making sure that the server response matches an expected response.

Today, Skyramp generates provider-side contract tests from request and response data supplied by the user. Generation of consumer-side contract tests is coming soon!

Generate a contract test for a single method

This section explains how you can use Skyramp to generate a contract test for a specific method of a REST API.

To reliably generate test cases, we require at least one of the following inputs:

  • An OpenAPI schema (JSON or YAML file)

  • Sample request and response data (JSON blob or JSON file)

In this guide, we'll use the OpenAPI schema approach. If you want more control over the generated body values, you can also do test generation from sample data (Example 1).

Contract Testing

This guide explains how to generate contract tests using the Skyramp CLI. Throughout this guide, we will demonstrate key capabilities using Skyramp’s Demo Shop API, a simple e-commerce API for product and order management. Learn more about the Demo Shop API.

If you haven’t already installed Skyramp, please refer to the instructions in the Installation Guide.

Overview

A contract test asserts that inter-application messages conform to a shared understanding that is documented in an API contract. In this context, every contract is between a client (consumer) and a server (provider). The consumer side is interested in making sure that the client can handle an expected response correctly. The provider side is interested in making sure that the server response matches an expected response.

Today, Skyramp generates provider-side contract tests from request and response data supplied by the user. Generation of consumer-side contract tests is coming soon!

Generate a contract test for a single method

This section explains how you can use Skyramp to generate a contract test for a specific method of a REST API.

To reliably generate test cases, we require at least one of the following inputs:

  • An OpenAPI schema (JSON or YAML file)

  • Sample request and response data (JSON blob or JSON file)

In this guide, we'll use the OpenAPI schema approach. If you want more control over the generated body values, you can also do test generation from sample data (Example 1).

Contract Testing

This guide explains how to generate contract tests using the Skyramp CLI. Throughout this guide, we will demonstrate key capabilities using Skyramp’s Demo Shop API, a simple e-commerce API for product and order management. Learn more about the Demo Shop API.

If you haven’t already installed Skyramp, please refer to the instructions in the Installation Guide.

Overview

A contract test asserts that inter-application messages conform to a shared understanding that is documented in an API contract. In this context, every contract is between a client (consumer) and a server (provider). The consumer side is interested in making sure that the client can handle an expected response correctly. The provider side is interested in making sure that the server response matches an expected response.

Today, Skyramp generates provider-side contract tests from request and response data supplied by the user. Generation of consumer-side contract tests is coming soon!

Generate a contract test for a single method

This section explains how you can use Skyramp to generate a contract test for a specific method of a REST API.

To reliably generate test cases, we require at least one of the following inputs:

  • An OpenAPI schema (JSON or YAML file)

  • Sample request and response data (JSON blob or JSON file)

In this guide, we'll use the OpenAPI schema approach. If you want more control over the generated body values, you can also do test generation from sample data (Example 1).

Python

Java

Typescript

To create a contract test for a single method, specify the method you want to test against in the command. In this example, we are using https://demoshop.skyramp.dev as the base URL to our service. When testing your service, replace it with the URL to the endpoint you want to test.

You can find the used API specification here.

skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema

This command generates a fully executable Python file (products_POST_contract_test.py). You can find additional information on the anatomy of Skyramp-generated tests here.

Explanation of Command

  • https://demoshop.skyramp.dev/api/v1/products: Defines the URL to the endpoint we aim to test.

  • -X (OR --method): Specifies the API method to test.

  • --language: Specifies the test output language. For contract testing, we currently support Python, Typescript, and Java.

  • --framework: Specifies the test execution framework of choice.

  • --api-schema: Points to the OpenAPI schema used to generate the test.

Adjustments

These flags will help you tune the basic contract test. Additional flags are explained here.

  • --request-data: Specify a sample JSON blob to use as the request body. This flag can be used without requiring an OpenAPI spec.

  • --asserts: Specify how many assertions Skyramp should generate on the response body for the contract test. Skyramp evaluates the endpoint to determine what values are expected, and then the test checks to see whether they are returned. You can find out more information about asserts here (Example 4).

    • Specifying all will return an assertion for every API response key available in the endpoint.

    • Specifying none will assert response code and check schema but will not return any body value assertions.

    • If this flag is not specified, Skyramp generates a test that checks the API schema and generates assertions for the HTTP response code and the first three response body values.

  • --response-status-code: Specify the expected status code. By default, Skyramp either asserts against the defined status code in the API specification or defaults to 20X.

  • --output: Specify the name of the generated test file.

  • --output-dir: Specify the directory to store the generated test file.

Execute the Contract Test

You can execute the generated tests without any additional adjustments to the code. However, based on the application you want to test, you can pass your authentication token to Skyramp Tests via an environment variable.

Set environment variable for authentication

To test against an application that requires authentication, pass your token using our environment variable. By default, Skyramp expects a Bearer Token but we support additional authentication methods (Example 3). If your API does not require any authentication, you can skip this step and just run the test.

Skyramp’s sample application requires a session identifier. Quickly obtain your session_id via the Demo Shop UI and set it as your authentication header. Additional information and ways to obtain the session_id can be found here.

export SKYRAMP_TEST_TOKEN=$your_auth_token

Run the Test

Run the test using Pytest. If you don’t have Pytest, refer to the Installation Guide for setup instructions:

python3 -m

Review Test Results

We are using Pytest’s default test output in this guide, printing a line for each test that is being run and listing all failures at the end. You can adjust the output behavior following this documentation.

Using the single POST method example (default asserts) for the /v1/products endpoint, the test passes.

Next Steps

Congratulations, you have just generated your first contract test! To learn more about how to adjust the test file, please go to the Test File Anatomy page.

Related topics

Python

Java

Typescript

To create a contract test for a single method, specify the method you want to test against in the command. In this example, we are using https://demoshop.skyramp.dev as the base URL to our service. When testing your service, replace it with the URL to the endpoint you want to test.

You can find the used API specification here.

skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema

This command generates a fully executable Python file (products_POST_contract_test.py). You can find additional information on the anatomy of Skyramp-generated tests here.

Explanation of Command

  • https://demoshop.skyramp.dev/api/v1/products: Defines the URL to the endpoint we aim to test.

  • -X (OR --method): Specifies the API method to test.

  • --language: Specifies the test output language. For contract testing, we currently support Python, Typescript, and Java.

  • --framework: Specifies the test execution framework of choice.

  • --api-schema: Points to the OpenAPI schema used to generate the test.

Adjustments

These flags will help you tune the basic contract test. Additional flags are explained here.

  • --request-data: Specify a sample JSON blob to use as the request body. This flag can be used without requiring an OpenAPI spec.

  • --asserts: Specify how many assertions Skyramp should generate on the response body for the contract test. Skyramp evaluates the endpoint to determine what values are expected, and then the test checks to see whether they are returned. You can find out more information about asserts here (Example 4).

    • Specifying all will return an assertion for every API response key available in the endpoint.

    • Specifying none will assert response code and check schema but will not return any body value assertions.

    • If this flag is not specified, Skyramp generates a test that checks the API schema and generates assertions for the HTTP response code and the first three response body values.

  • --response-status-code: Specify the expected status code. By default, Skyramp either asserts against the defined status code in the API specification or defaults to 20X.

  • --output: Specify the name of the generated test file.

  • --output-dir: Specify the directory to store the generated test file.

Execute the Contract Test

You can execute the generated tests without any additional adjustments to the code. However, based on the application you want to test, you can pass your authentication token to Skyramp Tests via an environment variable.

Set environment variable for authentication

To test against an application that requires authentication, pass your token using our environment variable. By default, Skyramp expects a Bearer Token but we support additional authentication methods (Example 3). If your API does not require any authentication, you can skip this step and just run the test.

Skyramp’s sample application requires a session identifier. Quickly obtain your session_id via the Demo Shop UI and set it as your authentication header. Additional information and ways to obtain the session_id can be found here.

export SKYRAMP_TEST_TOKEN=$your_auth_token

Run the Test

Run the test using Pytest. If you don’t have Pytest, refer to the Installation Guide for setup instructions:

python3 -m

Review Test Results

We are using Pytest’s default test output in this guide, printing a line for each test that is being run and listing all failures at the end. You can adjust the output behavior following this documentation.

Using the single POST method example (default asserts) for the /v1/products endpoint, the test passes.

Next Steps

Congratulations, you have just generated your first contract test! To learn more about how to adjust the test file, please go to the Test File Anatomy page.

Related topics

Python

Java

Typescript

To create a contract test for a single method, specify the method you want to test against in the command. In this example, we are using https://demoshop.skyramp.dev as the base URL to our service. When testing your service, replace it with the URL to the endpoint you want to test.

You can find the used API specification here.

skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema

This command generates a fully executable Python file (products_POST_contract_test.py). You can find additional information on the anatomy of Skyramp-generated tests here.

Explanation of Command

  • https://demoshop.skyramp.dev/api/v1/products: Defines the URL to the endpoint we aim to test.

  • -X (OR --method): Specifies the API method to test.

  • --language: Specifies the test output language. For contract testing, we currently support Python, Typescript, and Java.

  • --framework: Specifies the test execution framework of choice.

  • --api-schema: Points to the OpenAPI schema used to generate the test.

Adjustments

These flags will help you tune the basic contract test. Additional flags are explained here.

  • --request-data: Specify a sample JSON blob to use as the request body. This flag can be used without requiring an OpenAPI spec.

  • --asserts: Specify how many assertions Skyramp should generate on the response body for the contract test. Skyramp evaluates the endpoint to determine what values are expected, and then the test checks to see whether they are returned. You can find out more information about asserts here (Example 4).

    • Specifying all will return an assertion for every API response key available in the endpoint.

    • Specifying none will assert response code and check schema but will not return any body value assertions.

    • If this flag is not specified, Skyramp generates a test that checks the API schema and generates assertions for the HTTP response code and the first three response body values.

  • --response-status-code: Specify the expected status code. By default, Skyramp either asserts against the defined status code in the API specification or defaults to 20X.

  • --output: Specify the name of the generated test file.

  • --output-dir: Specify the directory to store the generated test file.

Execute the Contract Test

You can execute the generated tests without any additional adjustments to the code. However, based on the application you want to test, you can pass your authentication token to Skyramp Tests via an environment variable.

Set environment variable for authentication

To test against an application that requires authentication, pass your token using our environment variable. By default, Skyramp expects a Bearer Token but we support additional authentication methods (Example 3). If your API does not require any authentication, you can skip this step and just run the test.

Skyramp’s sample application requires a session identifier. Quickly obtain your session_id via the Demo Shop UI and set it as your authentication header. Additional information and ways to obtain the session_id can be found here.

export SKYRAMP_TEST_TOKEN=$your_auth_token

Run the Test

Run the test using Pytest. If you don’t have Pytest, refer to the Installation Guide for setup instructions:

python3 -m

Review Test Results

We are using Pytest’s default test output in this guide, printing a line for each test that is being run and listing all failures at the end. You can adjust the output behavior following this documentation.

Using the single POST method example (default asserts) for the /v1/products endpoint, the test passes.

Next Steps

Congratulations, you have just generated your first contract test! To learn more about how to adjust the test file, please go to the Test File Anatomy page.

Related topics

© 2025 Skyramp, Inc. All rights reserved.

© 2025 Skyramp, Inc. All rights reserved.

© 2025 Skyramp, Inc. All rights reserved.