Getting Started
Generating Tests
Generating Tests
Introduction
In the Writing Tests guide, you learned the basic anatomy of a test using Skyramp in Python. In this section you will learn about how Skyramp saves you time and expedites the testing process by automatically generating the test code you need. The Skyramp Generate functionality uses API schemas that you provide to quickly and automatically create the all the tests you need.
Generate Command
With the skyramp tester generate
command, generating tests for various API endpoints is easy. Customize test generation parameters through command-line flags like API specification file, Kubernetes service/Docker alias name, port number, output language, specific endpoint paths, and sample JSON data. Here's an example of generating tests for the REST path /artists
:
This command yields two Python test files:
Main Test Execution File (my-service_test.py
)
This file serves as the primary test execution file, callable in pipelines or test frameworks like Robot. Here’s a peek at its structure:
Test Scenario File (artists_test.py
)
This file contains test execution for functional and negative scenarios specific to the endpoint path (/artists
). Its structure is outlined below:
This file organization enhances modularity and clarity, simplifying test suite management and maintenance.
Note: The use of skyramp tester generate rest
here is an example of how to generate tests for a REST service and endpoint. Subcommands for tester generate
are available to perform across protocols (gRPC, GraphQL, etc.). For more details on available subcommands and their usage, refer to the tester generate
command documentation.
What’s Next
Now that you’ve generated your test files, it’s time to run them and validate your APIs. Check out the Running Tests guide to learn how to execute these test files and ensure your services meet expectations. Running tests helps catch potential issues early on, maintaining the reliability of your applications.