charlatan
0.5.0, released 2 years ago by betterment.dev
Configure and provide fake HTTP responses to the dio HTTP client for testing.
What it does
Allows you to configure fake HTTP responses for Dio based on HTTP methods and URI templates. It includes a custom HttpClientAdapter to route Dio requests through the configured fakes without using traditional mocking frameworks.
AI-written summary of version 0.5.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are writing tests for code that interacts with HTTP services via Dio.
- You want to avoid complex mocking libraries for testing network requests.
Skip it when
- You are not using the Dio HTTP client.
- You need a full-fledged backend server mock over actual sockets rather than an HTTP client adapter.
Strengths
- Makes testing Dio HTTP calls straightforward and readable.
- Supports URI templates and custom request matching logic.
Weaknesses
- Limited specifically to the Dio HTTP client.
- Not documented to support complex mock server scenarios beyond adapter-level faking.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 4
Add charlatan to dev_dependencies in pubspec.yaml.
final charlatan = Charlatan();
charlatan.whenGet('/users/{id}', charlatanResponse(body: { 'name': 'bilbo' }));
final dio = Dio()..httpClientAdapter = charlatan.toFakeHttpClientAdapter();Alternatives
Packages that do the same job and could replace charlatan.
- mock_supabase_http_client
A mock Supabase client for unit testing API calls without network requests.
71Compare - mockzilla
Run a local mock HTTP server inside your Flutter app for REST API testing.
71Compare - http_mock_adapter
A simple to use mocking package for Dio intended to be used in tests.
50Compare - network_image_mock
Utility for mocking Image.network responses in Flutter widget tests.
50Compare
Works with
Packages commonly used together with charlatan: ones it builds on, ones built on it, and its own family.