Bootstrapping SDK Tests

Automatically generate tests for your SDKs. Speakeasy can boostrap tests for all your operations including any new operations added in the future.

These tests use any examples available in your OpenAPI document if available, or autogenerate examples based on the field name, type, and format of your schemas.

Multiple tests per operation can be configured using the named examples detailed for your parameters, request bodies and responses.

By default these tests will run against a mock server to validate the correctness of your SDK’s serialization and deserialization.

Tests are boostrapped into a .speakeasy/tests.arazzo.yaml file in your SDK repo. Once the test exists it can be customized from that .speakeasy/tests.arazzo.yaml without being overwritten.

Prerequisites

The following are requirements for generating tests:

Enabling Test Generation

Navigate to your SDK repo and run the following command:

speakeasy configure tests

Test generation and mock API server generation will be enabled when the following exist in the generation section of the configuration.


Enable automated generation of tests for new operations found. When enabling for the first time this will generate tests for all operations in your OpenAPI document. Then going forward it will only generate tests for any operations not already found in your .speakeasy/tests.arazzo.yaml file.


gen.yaml
configVersion: 2.0.0
generation:
# ... other existing configuration ...
tests:
generateNewTests: true

After enabling test generation, if you wish to disable generation of tests for a specific operation, you can explicitly set x-speakeasy-test: false:

paths:
/example1:
get:
# This operation, without being explicitly disabled, will generate testing.
# ... operation configuration ...
/example2:
get:
# This operation will not generate testing.
# ... other operation configuration ...
x-speakeasy-test: false

Generated Test Location

Generated test files are written in language-specific locations, relative to the root of the SDK:

LanguageLocation
Gotests/
Pythontests/
TypeScriptsrc/__tests__

If the mock server is also generated, its output will be in a mockserver directory under these locations.

Running Tests

Run testing, via any of these options, depends on your desired use case:

For speakeasy run support, modify the Speakeasy workflow configuration (.speakeasy/workflow.yaml).

Enable running tests during Speakeasy workflows by adding to one or more of the targets in the targets section of the configuration.


Enable testing for the target.


workflow.yaml
targets:
example-target:
# ... other existing configuration ...
testing:
enabled: true

Next Steps