flutter_mock_web_server 1.0.0 flutter_mock_web_server: ^1.0.0 copied to clipboard
A null-safe mock_web_server package for Dart and Flutter
MockWebServer Plugin for Flutter #
A plugin that provides a mock web server to test HTTP requests and responses in Dart.
Getting Started
- Import the package:
import 'package:mock_web_server/mock_web_server.dart';
- Create an instance of
MockWebServer
:var server = MockWebServer();
- Start the server:
await server.start();
- Enqueue HTTP responses to the response queue using
enqueue()
. - Dispatch HTTP requests using
dispatchRequest()
and verify the responses received.
Example
var server = MockWebServer();
await server.start();
server.enqueue(httpCode: 200, body: '{"name": "John"}');
var response = await http.get(server.url);
expect(response.statusCode, equals(200));
expect(response.body, equals('{"name": "John"}'));
server.verifyRequestCount(1);
server.verifyNoMoreRequests();
await server.shutdown();