mockery 0.0.1+1

Simple mock recipes for making Flutter testing easier.

mockery #

A simple Dart package containing recipes for mocking objects in Dart and Flutter

Mocking HTTP Image Calls #

The first (and currently only) recipe here mocks a http call destined to retrieve an image and returns a one pixel image without touching the network. This is great for testing Flutter widgets that hit the network with things like Image.network.

Wrap the code making the http call with HttpOverrides.runZoned and pass in a reference to createMockImageHttpClient.

import 'dart:io';

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockery/mock_http_image.dart';

void main() {
  testWidgets('images are successfully mocked in http', (tester) async {
    HttpOverrides.runZoned(() async {
      await tester.pumpWidget(
          // The url doesn't matter, anything will do
          Image.network('https://www.example.com/images/image.png'));
    }, createHttpClient: createMockImageHttpClient);
  });
}
0
likes
20
pub points
0%
popularity

Simple mock recipes for making Flutter testing easier.

Repository (GitHub)
View/report issues

Uploader

matt.j.sullivan@gmail.com

License

BSD (LICENSE)

More

Packages that depend on mockery