fake_http_client
2.0.0, released 2 years ago by pasul.dev
A package for faking Dart and Flutter HttpClient responses for tests and unstable backends.
What it does
Allows developers to fake responses from the standard Dart and Flutter HttpClient. It is useful for integration tests and for local app development when dealing with unstable backends.
AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to write integration tests using standard HttpClient without hitting real servers.
- You want to mock network responses during development because the backend is unstable.
Skip it when
- You are using HTTP client libraries like http or dio that do not use dart:io HttpClient directly.
Strengths
- Great for integration tests.
- Helps during app development with unstable back-ends.
- Simple API integrating with HttpOverrides.
Weaknesses
- Only targets Dart/Flutter's HttpClient, not other third-party HTTP packages.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
not documented
class _EmptyResponseHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(_) => FakeHttpClient(
(request, client) => FakeHttpResponse(),
);
}
void main() {
group('HttpClient', () {
setUp(() {
HttpOverrides.global = _EmptyResponseHttpOverrides();
});
test('returns faked OK empty response for non-existing website', () async {
final client = HttpClient();
final request = await client.getUrl(Uri.parse('https://non-existing-site.com'));
final response = await request.close();
expect(response.statusCode, HttpStatus.ok);
expect(response.contentLength, 0);
});
});
}Alternatives
Packages that do the same job and could replace fake_http_client.
- flame_test
Classes and helpers for testing applications built with the Flame Engine.
80Compare - werkbank
A powerful tool that helps you develop, test, visualize, and organize your Flutter UI components.
77Compare - test_screenshot
Take screenshots during your flutter unit tests for debugging
41Compare - network_image_mock
Utility for mocking Image.network responses in Flutter widget tests.
50Compare