Overview
The Auth0 Go SDK uses HTTP recordings for testing, allowing you to:- Test without hitting live Auth0 APIs
- Create fast, reliable, and repeatable tests
- Avoid rate limits and network dependencies
- Record real API interactions for playback
Test Environment Setup
Prerequisites
Running Tests with HTTP Recordings
The SDK includes HTTP recordings for all tests:- Starts a WireMock Docker container
- Loads HTTP recordings from
test/data/recordings/ - Runs tests against the mock server
- Stops the container when done
Running Tests Against Real Auth0 Tenant
For end-to-end testing against a live Auth0 tenant:Environment Variables for E2E Tests
Create a.env file in the project root:
You need two M2M applications:
- Management API: For management API operations (clients, users, etc.)
- Authentication API: For authentication API operations (tokens, user info, etc.)
Recording New HTTP Interactions
When adding new tests or updating existing ones:- Run tests against your real Auth0 tenant
- Record all HTTP requests and responses
- Save recordings to
test/data/recordings/
Writing Tests with the SDK
Basic Test Structure
Testing with Subtests
Testing Pagination
Testing Error Conditions
Using WireMock for Custom Tests
You can run WireMock independently for custom test scenarios:Test Helpers
Create reusable test helpers:Best Practices
Use Recordings for CI
Always use HTTP recordings in CI/CD pipelines to avoid rate limits and ensure consistent, fast test execution.
Clean Up Resources
Always clean up test resources using
defer or t.Cleanup() to avoid polluting your test tenant.Use Unique Names
Include test name or timestamp in resource names to avoid conflicts:
Skip When Needed
Skip tests when credentials aren’t available:
Makefile Test Targets
The SDK provides several make targets for testing:Test Configuration
The test commands use these settings:- Coverage mode:
atomic(safe for parallel tests) - Coverage output:
coverage.out - E2E timeout: 20 minutes
- Recordings directory:
test/data/recordings/
Debugging Tests
Enable debug mode for verbose output:Common Testing Patterns
Table-Driven Tests
Related Topics
- Error Handling - Handle test errors
- Pagination - Test pagination
- Request Options - Configure test requests