Customizing SDK Tests
Test Generation Overview
When generateNewTests
is enabled in the .speakeasy/gen.yaml
file, workflows for any newly discovered operations will automatically be created in the .speakeasy/tests.arazzo.yaml
file during the next generation. Tests will then be generated based on these workflows.
Note that for tests to actually be generated during speakeasy run
, the generateTests
setting must also be enabled. Both settings can be enabled by running speakeasy configure tests
.
Disable auto generation of tests for specific operations
To disable auto generation of tests for specific operations, the x-speakeasy-test
extension can be added to the operation in the OpenAPI document:
Alternatively, if a workflow/test already exists that references the operation in the .speakeasy/tests.arazzo.yaml
file, then no new workflow will be created for the operation.
Automatic Test Synchronization
Speakeasy synchronizes workflows in the .speakeasy/tests.arazzo.yaml
file based on the presence of the x-speakeasy-test-rebuild
extension. When generateNewTests
is enabled, Speakeasy automatically applies this extension to newly created workflows. The extension indicates that the workflows should remain synchronized with any subsequent changes to the OpenAPI specification.
Auto-sync with OpenAPI Changes (x-speakeasy-test-rebuild: true
)
When set to true
, the workflow will automatically be kept in sync with the state of the operation in the OpenAPI specification. The test will be rebuilt each time the spec changes, incorporating:
- New parameters
- Request body field changes
- Response body updates
- Updates to examples
This is useful if you want Speakeasy to automatically maintain your tests as your API evolves.
Manual Test Maintenance (x-speakeasy-test-rebuild: false
or omitted)
When the extension is omitted or set to false
, the workflow needs to be maintained manually and won’t sync with the OpenAPI specification. This gives you complete control over the test content and is useful when:
- Writing custom tests with specific logic
- Maintaining test state independent from the OpenAPI document
- Catching breaking changes or regressions in the API behavior
Grouping tests
By default, all tests will be generated into a single file related to the main SDK class for example sdk.test.ts
, test_sdk.py
, or SDKTest.java
. This can be configured by adding a x-speakeasy-test-group
extension to the workflow which will determine which tests will be grouped together in seperate test files.
Generate tests only for specific targets
By default, all tests will be generated for all supported targets. Using the x-speakeasy-test-targets
or x-speakeasy-test-targets-exclude
extensions, it is possible to generate tests only for specific targets. This may be useful if tests are either not needed for certain languages or they may be failing in a certain language.
or
Customizing SDK Test Manifests
Directly modifying SDK tests is not common, but it is possible to customize the actual content of an existing SDK test by modifying the .speakeasy/tests.arazzo.yaml
file.
To learn more about these kinds of modifications see here.
Next Steps
Bootstrapping tests again from scratch
Once the original tests.arazzo.yaml
document is bootstrapped, the Arazzo document will only be modified automatically when new operations are detected and generateNewTests: true
is set in your ./speakeasy/gen.yaml
, new tests will be bootstrapped for these new operations. But pre-bootstrapped tests will be left alone.
If you want to bootstrap all workflows in the Arazzo document from scratch again (for example to match changes to operations or examples in your spec), run the following command:
You can also selectively bootstrap individual tests by:
- Deleting the specific workflow from the arazzo doc in
.speakeasy/tests.arazzo.yaml
- Removing the corresponding entry in
.speakeasy/gen.lock
undergeneratedTests
For example, to bootstrap a test for the createLink
operation again, delete its entry in the gen.lock file:
This approach preserves any other manual changes you’ve made to your arazzo doc.
Last updated on