패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소LukaGiorgadze/http-mock-adapter

http-mock-adapter

테스트에서 사용하기 위해 설계된 Dio용 간단한 사용법의 모킹 패키지입니다.

http-mock-adapter 프로젝트 이미지
스타
69
포크
44
최근 푸시(UTC)
2026. 7. 1.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

http-mock-adapter

Package Version Style: Lints Dart CI Publish Package LICENSE codecov

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.

Luka Giorgadze GitHub avatar
GitHub 작성자

Luka Giorgadze ↗

The road to wisdom? Well, it's plain and simple to express: err and err and err again, but less and less and less.

Georgia, Tbilisi공식 웹사이트 ↗
언어Dart

분류

사용 중인 의존성

의존성 목록 7 개

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗