setup-sdk-testing
Skill17 starsChanged 10 months agoApache-2.0View on GitHub
Use when setting up SDK testing, configuring contract tests, writing Arazzo test workflows, or running integration tests. Triggers on "SDK testing", "test SDK", "contract testing", "Arazzo tests", "integration tests", "speakeasy test", "mock server", "test generation", "ResponseValidationError
- Reads credentials
In this repository15 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- configure-sdk-optionsSkill
- customize-sdk-hooksSkill
- diagnose-generation-failureSkill
- extract-openapi-from-codeSkill
- generate-mcp-serverSkill
- generate-terraform-providerSkill
- improve-sdk-namingSkill
- manage-openapi-overlaysSkill
- orchestrate-multi-repo-sdksSkill
- orchestrate-multi-target-sdksSkill
- speakeasy-contextSkill
- start-new-sdk-projectSkill
- writing-openapi-specsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
19 rules. About 0 are common, 11 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 121
Run the generated tests:
- Very specific: line 131
Create or edit .speakeasy/tests.arazzo.yaml:
- Distinctive: line 180
Run the custom tests:
- Distinctive: line 204
Use an overlay to disable a generated test without deleting it:
- Distinctive: line 317
Do NOT: run integration tests with destructive operations in production -- always use a test/staging environment
- Very specific: line 327
Missing required fields: Check your spec's required arrays match actual API responses
- Very specific: line 328
Type mismatches: Verify type and format fields in schema definitions
- Distinctive: line 337
Check that all environment variables are set in CI secrets
- Distinctive: line 338
Verify the CI runner has network access to mock server ports
- Distinctive: line 339
Ensure the Speakeasy CLI version matches between local and CI
- Distinctive: line 343
Update the Speakeasy CLI:
- Distinctive: line 351
Check for port conflicts on the default mock server port
- Very specific: line 352
Ensure the OpenAPI spec is valid: speakeasy lint openapi -s spec.yaml
- Very specific: line 353
Verify generateTests: true is set in gen.yaml and the SDK has been regenerated
- Very specific: line 357
Verify the file is at .speakeasy/tests.arazzo.yaml
- Very specific: line 358
Check that operationId values match those in your OpenAPI spec exactly
- Distinctive: line 363
Add retry logic for network-dependent tests
- Distinctive: line 364
Use unique resource names with timestamps to avoid collisions
- Very specific: line 365
Ensure cleanup runs even on test failure (use finally or afterEach)
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
setup-sdk-testing
Set up and run tests for Speakeasy-generated SDKs using contract testing, custom Arazzo workflows, or integration tests against live APIs.
Content Guides
| Topic | Guide |
| Arazzo Reference | content/arazzo-reference.md |
The Arazzo reference provides complete syntax for workflows, steps, success criteria, environment variables, and chaining operations.
When to Use
- Setting up automated testing for a generated SDK
- Enabling contract test generation via
gen.yaml - Writing custom multi-step API workflow tests with Arazzo
- Configuring integration tests against a live API
- Debugging
ResponseValidationErroror test failures - User says: "test SDK", "contract testing", "Arazzo tests", "speakeasy test", "mock server", "test generation"
Inputs
| Input | Required | Description |
gen.yaml | Yes | Generation config; contract testing is enabled here |
| OpenAPI spec | Yes | The API spec the SDK is generated from |
| Target language | Yes | typescript, python, go, or java (contract test support) |
.speakeasy/tests.arazzo.yaml | No | Custom Arazzo test definitions |
| Live API credentials | No | Required only for integration testing |
Outputs
| Output | Location |
| Generated contract tests | tests/ directory in SDK output |
| Mock server config | Auto-generated alongside contract tests |
| Arazzo test results | Terminal output from speakeasy test |
| CI workflow | .github/workflows/ (if integration testing configured) |
Prerequisites
- Speakeasy CLI installed and authenticated (
speakeasy auth login) - A working SDK generation setup (
gen.yaml+ OpenAPI spec) - For integration tests: API credentials as environment variables
Decision Framework
Pick the right testing approach based on what you need:
| Need | Approach | Effort |
| Verify SDK types and methods match the API contract | Contract testing | Low (auto-generated) |
| Test multi-step API workflows (create then verify) | Custom Arazzo tests | Medium |
| Validate against a live API with real data | Integration testing | High |
| Catch regressions on every SDK regeneration | Contract testing + CI | Low |
| Test authentication flows end-to-end | Integration testing | High |
| Verify chained operations with data dependencies | Custom Arazzo tests | Medium |
Start with contract testing. It is auto-generated and catches the most common issues. Add custom Arazzo tests for workflow coverage, and integration tests only when live API validation is required.
Command
Enable Contract Testing
Add to gen.yaml:
generation:
tests:
generateTests: trueThen regenerate the SDK:
speakeasy run --output consoleRun Tests
# Run all Arazzo-defined tests (contract + custom)
speakeasy test
# Run tests for a specific target
speakeasy test --target my-typescript-sdk
# Run with verbose output for debugging
speakeasy test --verboseRun via CI
Contract tests run automatically in the Speakeasy GitHub Actions workflow when test generation is enabled. No additional CI configuration is needed for contract tests.
Example
1. Contract Testing (Quick Start)
Enable test generation in gen.yaml:
generation:
tests:
generateTests: trueRegenerate the SDK:
speakeasy run --output consoleRun the generated tests:
speakeasy testThe CLI generates tests from your OpenAPI spec, creates a mock server that returns spec-compliant responses, and validates that the SDK correctly handles requests and responses.
2. Custom Arazzo Tests
Create or edit .speakeasy/tests.arazzo.yaml:
arazzo: 1.0.0
info:
title: Custom SDK Tests
version: 1.0.0
sourceDescriptions:
- name: my-api
type: openapi
url: ./openapi.yaml
workflows:
- workflowId: create-and-verify-resource
steps:
- stepId: create-resource
operationId: createResource
requestBody:
payload:
name: "test-resource"
type: "example"
successCriteria:
- condition: $statusCode == 201
outputs:
resourceId: $response.body#/id
- stepId: get-resource
operationId: getResource
parameters:
- name: id
in: path
value: $steps.create-resource.outputs.resourceId
successCriteria:
- condition: $statusCode == 200
- condition: $response.body#/name == "test-resource"
- workflowId: list-and-filter
steps:
- stepId: list-resources
operationId: listResources
parameters:
- name: limit
in: query
value: 10
successCriteria:
- condition: $statusCode == 200Run the custom tests:
speakeasy testUsing Environment Variables in Arazzo Tests
Reference environment variables for sensitive values:
steps:
- stepId: authenticated-request
operationId: getProtectedResource
parameters:
- name: Authorization
in: header
value: Bearer $env.API_TOKEN
successCriteria:
- condition: $statusCode == 200Disabling a Specific Test
Use an overlay to disable a generated test without deleting it:
overlay: 1.0.0
info:
title: Disable flaky test
actions:
- target: $["workflows"][?(@.workflowId=="flaky-test")]
update:
x-speakeasy-test:
disabled: true3. Integration Testing
For live API testing, use the SDK factory pattern:
TypeScript example:
import { SDK } from "./src";
function createTestClient(): SDK {
return new SDK({
apiKey: process.env.TEST_API_KEY,
serverURL: process.env.TEST_API_URL ?? "https://api.example.com",
});
}
describe("Integration Tests", () => {
const client = createTestClient();
it("should list resources", async () => {
const result = await client.resources.list({ limit: 5 });
expect(result.statusCode).toBe(200);
expect(result.data).toBeDefined();
});
it("should create and delete resource", async () => {
// Create
const created = await client.resources.create({ name: "integration-test" });
expect(created.statusCode).toBe(201);
// Cleanup
const deleted = await client.resources.delete({ id: created.data.id });
expect(deleted.statusCode).toBe(204);
});
});Python example:
import os
import pytest
from my_sdk import SDK
@pytest.fixture
def client():
return SDK(
api_key=os.environ["TEST_API_KEY"],
server_url=os.environ.get("TEST_API_URL", "https://api.example.com"),
)
def test_list_resources(client):
result = client.resources.list(limit=5)
assert result.status_code == 200
assert result.data is not None
@pytest.mark.cleanup
def test_create_and_delete(client):
created = client.resources.create(name="integration-test")
assert created.status_code == 201
try:
fetched = client.resources.get(id=created.data.id)
assert fetched.data.name == "integration-test"
finally:
client.resources.delete(id=created.data.id)GitHub Actions CI for integration tests:
name: Integration Tests
on:
schedule:
- cron: "0 6 * * 1-5"
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: speakeasy-api/sdk-generation-action@v15
with:
speakeasy_version: latest
- run: speakeasy test
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
- name: Run integration tests
run: npm test -- --grep "integration"
env:
TEST_API_KEY: ${{ secrets.TEST_API_KEY }}
TEST_API_URL: ${{ secrets.TEST_API_URL }}What NOT to Do
- Do NOT skip contract testing and jump straight to integration tests -- contract tests are free and catch most issues
- Do NOT hardcode API keys or secrets in Arazzo test files -- use
$env.VARIABLE_NAMEsyntax - Do NOT modify auto-generated test files directly -- they are overwritten on regeneration; use custom Arazzo tests instead
- Do NOT disable failing contract tests without investigating -- a
ResponseValidationErrorusually means the spec and API are out of sync - Do NOT run integration tests with destructive operations in production -- always use a test/staging environment
- Do NOT assume all languages support contract testing -- currently supported: TypeScript, Python, Go, Java
Troubleshooting
ResponseValidationError in contract tests
The SDK response does not match the OpenAPI spec. Common causes:
- Spec is outdated: Regenerate from the latest API spec
- Missing required fields: Check your spec's
requiredarrays match actual API responses - Type mismatches: Verify
typeandformatfields in schema definitions
# Regenerate with latest spec and re-run tests
speakeasy run --output console && speakeasy test --verboseTests pass locally but fail in CI
- Check that all environment variables are set in CI secrets
- Verify the CI runner has network access to mock server ports
- Ensure the Speakeasy CLI version matches between local and CI
speakeasy test command not found
Update the Speakeasy CLI:
speakeasy updateMock server fails to start
- Check for port conflicts on the default mock server port
- Ensure the OpenAPI spec is valid:
speakeasy lint openapi -s spec.yaml - Verify
generateTests: trueis set ingen.yamland the SDK has been regenerated
Custom Arazzo test not running
- Verify the file is at
.speakeasy/tests.arazzo.yaml - Check that
operationIdvalues match those in your OpenAPI spec exactly - Validate YAML syntax -- indentation errors are the most common cause
Integration tests intermittently fail
- Add retry logic for network-dependent tests
- Use unique resource names with timestamps to avoid collisions
- Ensure cleanup runs even on test failure (use
finallyorafterEach)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

