Skip to content
pubscout

charlatan

0.5.0, released 2 years ago by betterment.dev

Configure and provide fake HTTP responses to the dio HTTP client for testing.

WASM-ready
$ flutter pub add charlatan
Source repository

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.

Works with

Packages commonly used together with charlatan: ones it builds on, ones built on it, and its own family.