Package Version Style: Pedantic Dart CI Publish Package LICENSE


Dio HTTP mock adapter for Dart/Flutter (compatible with Mockito).

Sometimes, testing classes which are dependent on Dio requests are really tricky and require lots of boilerplate, this is where http_mock_adapter comes in, to make Dio request testing more flexible than it has ever been.

By simply defining requests with their methods and responses by using chains of our DioAdapter and replacing Dio's httpClientAdapter with your custom mocked adapter, you will be able to mock basically any request that Dio can support.

Moreover, http_mock_adapter package supports request mocking with interceptors which are created via DioInterceptor class, so instead of replacing Dio's httpClientAdapter, you can add your mocked interceptor inside the dio.interceptors list by using its add method.

You can find example in examples section of http_mock_adapter package.

See the following DEV/Medium article for more background.


Here is the basic usage scenario of the package (via DioAdapter):

import 'package:dio/dio.dart';
import 'package:http_mock_adapter/http_mock_adapter.dart';

void main() async {
  final dio = Dio();
  final dioAdapter = DioAdapter();

  dio.httpClientAdapter = dioAdapter;

  const path = '';

        (request) => request.reply(200, {'message': 'Successfully mocked GET!'}),
        (request) => request.reply(200, {'message': 'Successfully mocked POST!'}),

  final onGetResponse = await dio.get(path);
  print(; // {message: Successfully mocked GET!}

  final onPostResponse = await;
  print(; // {message: Successfully mocked POST!}


Depend on it

Add this to your package's pubspec.yaml file:

  http_mock_adapter: ^0.2.1

Install it

You can install packages from the command line:

with pub:

$ pub get

with flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:http_mock_adapter/http_mock_adapter.dart';


All notable changes to this project will be documented in the file.


See the AUTHORS file for information regarding the authors of the project.


http-mock-adapter is licensed under the permissive MIT License (LICENSE).


For information regarding contributions, please refer to file.