Contract Test
Examples
Generation Examples
In this section, we will go over how to customize the Skyramp CLI test generation command to achieve specific use cases for your test execution.
Generation Examples
In this section, we will go over how to customize the Skyramp CLI test generation command to achieve specific use cases for your test execution.
Generation Examples
In this section, we will go over how to customize the Skyramp CLI test generation command to achieve specific use cases for your test execution.
Python
Java
Typescript
Generation from sample data
Instead of using your API specification, Skyramp enables users to also generate contract tests based on sample request and response data. This allows users to quickly test specific scenarios that depend on specific data.
request.json
{
"category": "electronics",
"description": "speaker",
"image_url": "photo",
"in_stock": false,
"name": "boombox",
"price": 25
response.json
{
"category": "electronics",
"created_at": "2025-02-25T10:54:22-05:00",
"description": "speaker",
"image_url": "photo",
"in_stock": false,
"name": "boombox",
"price": 25,
"product_id": 0
Command to generate from sample data
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--request-data @request.json \
--response-data
Test generation for Robot framework
Skyramp also supports the Robot framework in Python. This section shows you how to generate and execute tests using it instead of Pytest.
Command to generate for Robot
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework robot \
--api-schema
This command generates two files:
products_POST_contract_test.py
products_POST_contract_test.robot
(simple Robot wrapper file)
Execute the contract test
Ensure that authentication is properly set up. Run the test using the Robot Framework. You can call the generated Python file either in an existing robot file of yours or leverage the simple wrapper file we generate.
# Prerequisites
pip3 install robotframework
# Execution of contract test for products/POST
python3 -m
The results will be outputted following the typical stdout
from Robot. You can find more information on the generated outputs in the Robot documentation.
Specify the form parameters for a POST request
For POST requests, you can also provide form params instead of an API schema or sample request data to define the request body.
Command to generate from form parameters
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--form-params category=electronics \
--form-params description=speaker \
--form-params image_url=photo \
--form-params in_stock=false \
--form-params name=boombox \
--form-params price=25 \
--response-data
Definition of expected response status code
By default, Skyramp assumes the expected status code to be 20X
. You can quickly change this by specifying the expected status code in the flags.
Command to change response status code
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--response-status-code 40X \
--api-schema
Change the authentication type
By default, Skyramp assumes a Bearer token. You can define the key of your authentication header with the auth-header
flag.
Command to change authentication type
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--auth-header X-API-KEY \
--api-schema
Specify contract test path parameters for a single method
Skyramp also allows you to define path parameters in the generation command. The path-param
flag will override all relevant path parameters with your specified value.
Command to specify path parameters
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products/{product_id} \
-X PUT \
--language python \
--framework pytest \
--path-params product_id=2 \
--api-schema
Specify contract test path parameters for entire endpoints
You can also specify path params if you test an entire endpoint. Skyramp overrides the path param value for all methods that have a path parameter in the path with the value you specify.
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
--language python \
--framework pytest \
--path-params product_id=2 \
--api-schema
Specify contract test query parameters
You can provide specific query parameters to the generation command to ensure your expected outcome.
Command to specify query parameters
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X GET \
--language python \
--framework pytest \
--query-params limit=5 \
--query-params order=desc \
--api-schema
Change the test execution runtime to Docker
Instead of using “local” execution, Skyramp also supports seamless support for testing applications in your Docker network. This allows you to test your services without worrying about network configurations and port mapping while developing locally.
During test execution, we automatically deploy our Skyramp Worker into the specified Docker network and send the requests from within the network.
Command to change test execution runtime
skyramp generate contract rest http://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--runtime docker \
--docker-network api-insight_default \
--docker-skyramp-port 35142 \
--api-schema
Command to specify test name and directory
The additional flags allow you to specify the directory and file name of the generated test.
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--output post_products_contract_test.spec.ts \
--output-dir
Force overwrite of test files
If you are overwriting the file you can force it with this flag
Command to force overwrite test file
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--overwrite
Deploy the Skyramp Dashboard
Skyramp also offers a simple dashboard to collect and help you analyze your test results. The Skyramp Dashboard is a lightweight Docker image that will automatically be brought up when executing the test. Please specify the --deploy-dashboard
flag in the generation command.
Post execution, the dashboard will be available under http://localhost:3000/tests.
Command to deploy Skyramp Dashboard
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--deploy-dashboard
Change the body value asserts
The assert flag allows you to specify how the generated code asserts the body values of the response. By default, Skyramp generates value asserts for the first 3 body values. You can choose to generate asserts for all body values (--asserts all
) or no values at all (--asserts none
).
Command to assert for all body values
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--asserts
Command to assert for no body values
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--asserts
Python
Java
Typescript
Generation from sample data
Instead of using your API specification, Skyramp enables users to also generate contract tests based on sample request and response data. This allows users to quickly test specific scenarios that depend on specific data.
request.json
{
"category": "electronics",
"description": "speaker",
"image_url": "photo",
"in_stock": false,
"name": "boombox",
"price": 25
response.json
{
"category": "electronics",
"created_at": "2025-02-25T10:54:22-05:00",
"description": "speaker",
"image_url": "photo",
"in_stock": false,
"name": "boombox",
"price": 25,
"product_id": 0
Command to generate from sample data
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--request-data @request.json \
--response-data
Test generation for Robot framework
Skyramp also supports the Robot framework in Python. This section shows you how to generate and execute tests using it instead of Pytest.
Command to generate for Robot
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework robot \
--api-schema
This command generates two files:
products_POST_contract_test.py
products_POST_contract_test.robot
(simple Robot wrapper file)
Execute the contract test
Ensure that authentication is properly set up. Run the test using the Robot Framework. You can call the generated Python file either in an existing robot file of yours or leverage the simple wrapper file we generate.
# Prerequisites
pip3 install robotframework
# Execution of contract test for products/POST
python3 -m
The results will be outputted following the typical stdout
from Robot. You can find more information on the generated outputs in the Robot documentation.
Specify the form parameters for a POST request
For POST requests, you can also provide form params instead of an API schema or sample request data to define the request body.
Command to generate from form parameters
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--form-params category=electronics \
--form-params description=speaker \
--form-params image_url=photo \
--form-params in_stock=false \
--form-params name=boombox \
--form-params price=25 \
--response-data
Definition of expected response status code
By default, Skyramp assumes the expected status code to be 20X
. You can quickly change this by specifying the expected status code in the flags.
Command to change response status code
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--response-status-code 40X \
--api-schema
Change the authentication type
By default, Skyramp assumes a Bearer token. You can define the key of your authentication header with the auth-header
flag.
Command to change authentication type
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--auth-header X-API-KEY \
--api-schema
Specify contract test path parameters for a single method
Skyramp also allows you to define path parameters in the generation command. The path-param
flag will override all relevant path parameters with your specified value.
Command to specify path parameters
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products/{product_id} \
-X PUT \
--language python \
--framework pytest \
--path-params product_id=2 \
--api-schema
Specify contract test path parameters for entire endpoints
You can also specify path params if you test an entire endpoint. Skyramp overrides the path param value for all methods that have a path parameter in the path with the value you specify.
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
--language python \
--framework pytest \
--path-params product_id=2 \
--api-schema
Specify contract test query parameters
You can provide specific query parameters to the generation command to ensure your expected outcome.
Command to specify query parameters
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X GET \
--language python \
--framework pytest \
--query-params limit=5 \
--query-params order=desc \
--api-schema
Change the test execution runtime to Docker
Instead of using “local” execution, Skyramp also supports seamless support for testing applications in your Docker network. This allows you to test your services without worrying about network configurations and port mapping while developing locally.
During test execution, we automatically deploy our Skyramp Worker into the specified Docker network and send the requests from within the network.
Command to change test execution runtime
skyramp generate contract rest http://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--runtime docker \
--docker-network api-insight_default \
--docker-skyramp-port 35142 \
--api-schema
Command to specify test name and directory
The additional flags allow you to specify the directory and file name of the generated test.
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--output post_products_contract_test.spec.ts \
--output-dir
Force overwrite of test files
If you are overwriting the file you can force it with this flag
Command to force overwrite test file
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--overwrite
Deploy the Skyramp Dashboard
Skyramp also offers a simple dashboard to collect and help you analyze your test results. The Skyramp Dashboard is a lightweight Docker image that will automatically be brought up when executing the test. Please specify the --deploy-dashboard
flag in the generation command.
Post execution, the dashboard will be available under http://localhost:3000/tests.
Command to deploy Skyramp Dashboard
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--deploy-dashboard
Change the body value asserts
The assert flag allows you to specify how the generated code asserts the body values of the response. By default, Skyramp generates value asserts for the first 3 body values. You can choose to generate asserts for all body values (--asserts all
) or no values at all (--asserts none
).
Command to assert for all body values
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--asserts
Command to assert for no body values
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--asserts
Python
Java
Typescript
Generation from sample data
Instead of using your API specification, Skyramp enables users to also generate contract tests based on sample request and response data. This allows users to quickly test specific scenarios that depend on specific data.
request.json
{
"category": "electronics",
"description": "speaker",
"image_url": "photo",
"in_stock": false,
"name": "boombox",
"price": 25
response.json
{
"category": "electronics",
"created_at": "2025-02-25T10:54:22-05:00",
"description": "speaker",
"image_url": "photo",
"in_stock": false,
"name": "boombox",
"price": 25,
"product_id": 0
Command to generate from sample data
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--request-data @request.json \
--response-data
Test generation for Robot framework
Skyramp also supports the Robot framework in Python. This section shows you how to generate and execute tests using it instead of Pytest.
Command to generate for Robot
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework robot \
--api-schema
This command generates two files:
products_POST_contract_test.py
products_POST_contract_test.robot
(simple Robot wrapper file)
Execute the contract test
Ensure that authentication is properly set up. Run the test using the Robot Framework. You can call the generated Python file either in an existing robot file of yours or leverage the simple wrapper file we generate.
# Prerequisites
pip3 install robotframework
# Execution of contract test for products/POST
python3 -m
The results will be outputted following the typical stdout
from Robot. You can find more information on the generated outputs in the Robot documentation.
Specify the form parameters for a POST request
For POST requests, you can also provide form params instead of an API schema or sample request data to define the request body.
Command to generate from form parameters
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--form-params category=electronics \
--form-params description=speaker \
--form-params image_url=photo \
--form-params in_stock=false \
--form-params name=boombox \
--form-params price=25 \
--response-data
Definition of expected response status code
By default, Skyramp assumes the expected status code to be 20X
. You can quickly change this by specifying the expected status code in the flags.
Command to change response status code
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--response-status-code 40X \
--api-schema
Change the authentication type
By default, Skyramp assumes a Bearer token. You can define the key of your authentication header with the auth-header
flag.
Command to change authentication type
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--auth-header X-API-KEY \
--api-schema
Specify contract test path parameters for a single method
Skyramp also allows you to define path parameters in the generation command. The path-param
flag will override all relevant path parameters with your specified value.
Command to specify path parameters
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products/{product_id} \
-X PUT \
--language python \
--framework pytest \
--path-params product_id=2 \
--api-schema
Specify contract test path parameters for entire endpoints
You can also specify path params if you test an entire endpoint. Skyramp overrides the path param value for all methods that have a path parameter in the path with the value you specify.
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
--language python \
--framework pytest \
--path-params product_id=2 \
--api-schema
Specify contract test query parameters
You can provide specific query parameters to the generation command to ensure your expected outcome.
Command to specify query parameters
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X GET \
--language python \
--framework pytest \
--query-params limit=5 \
--query-params order=desc \
--api-schema
Change the test execution runtime to Docker
Instead of using “local” execution, Skyramp also supports seamless support for testing applications in your Docker network. This allows you to test your services without worrying about network configurations and port mapping while developing locally.
During test execution, we automatically deploy our Skyramp Worker into the specified Docker network and send the requests from within the network.
Command to change test execution runtime
skyramp generate contract rest http://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--runtime docker \
--docker-network api-insight_default \
--docker-skyramp-port 35142 \
--api-schema
Command to specify test name and directory
The additional flags allow you to specify the directory and file name of the generated test.
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--output post_products_contract_test.spec.ts \
--output-dir
Force overwrite of test files
If you are overwriting the file you can force it with this flag
Command to force overwrite test file
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--overwrite
Deploy the Skyramp Dashboard
Skyramp also offers a simple dashboard to collect and help you analyze your test results. The Skyramp Dashboard is a lightweight Docker image that will automatically be brought up when executing the test. Please specify the --deploy-dashboard
flag in the generation command.
Post execution, the dashboard will be available under http://localhost:3000/tests.
Command to deploy Skyramp Dashboard
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--deploy-dashboard
Change the body value asserts
The assert flag allows you to specify how the generated code asserts the body values of the response. By default, Skyramp generates value asserts for the first 3 body values. You can choose to generate asserts for all body values (--asserts all
) or no values at all (--asserts none
).
Command to assert for all body values
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--asserts
Command to assert for no body values
skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
-X POST \
--language python \
--framework pytest \
--api-schema https://demoshop.skyramp.dev/openapi.json \
--asserts