http-mock-adapter
テストで使用することを目的とした、Dio用の簡単なモックパッケージです。
- スター
- 69
- フォーク
- 44
- 最終プッシュ(UTC)
- 2026/07/01
- プロジェクト状態
- 公開中
元の README
以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
http-mock-adapter
Description
http_mock_adapter is a simple to use mocking package for Dio intended to be used in tests. It provides various types and methods to declaratively mock request-response communication.
Usage
Here is a very basic usage scenario:
import 'package:dio/dio.dart';
import 'package:http_mock_adapter/http_mock_adapter.dart';
void main() async {
//// Exact body check
// final dio = Dio(BaseOptions(contentType: Headers.jsonContentType));
// dioAdapter = DioAdapter(
// dio: dio,
// matcher: const FullHttpRequestMatcher(needsExactBody: true),
// );
// Basic setup
final dio = Dio(BaseOptions());
final dioAdapter = DioAdapter(dio: dio);
const path = 'https://example.com';
dioAdapter.onGet(
path,
(server) => server.reply(
200,
{'message': 'Success!'},
// Reply would wait for one-sec before returning data.
delay: const Duration(seconds: 1),
),
);
final response = await dio.get(path);
print(response.data); // {message: Success!}
}
Real-world example
The intended usage domain is in tests when trying to simulate behavior of request-response communication with a server. The example portrays a decent use case of how one might make good use of the package.
Installing
Quick install
You can quickly install the package from the command-line:
With dart:
$ dart pub add --dev http_mock_adapter
...
With flutter:
$ flutter pub add --dev http_mock_adapter
...
Manual install
Depend on it
Add this to your package's pubspec.yaml file:
dev_dependencies:
http_mock_adapter: ^0.6.1
Install it
You can then install the package from the command-line:
With dart:
$ dart pub get
...
With flutter:
$ flutter pub get
...
Alternatively, your editor might support dart 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';
Changelog
All notable changes to this project will be documented in the CHANGELOG.md file.
Authors
See the AUTHORS file for information regarding the authors of the project.
License
http-mock-adapter is licensed under the permissive MIT License (LICENSE).
Contribution
Made with contrib.rocks.
For information regarding contributions, please refer to CONTRIBUTING.md file.
カテゴリー
使用している依存関係
依存関係一覧 7 件
- collection
^1.17.1 - dio
^5.3.2 - http_parser
^4.0.2 - logger
^2.0.2+1 - lints開発用
>=2.1.1 - test開発用
^1.24.6 - fake_async開発用
^1.3.1
プロジェクトに合うリポジトリを選ぶには?
用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。
- 名前・作者・説明で検索し、技術トピックで絞り込みます。
- スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
- 利用前に GitHub で README、ライセンス、Issues を確認します。
情報源と管理
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗