All Projects → stelynx → network_image_mock

stelynx / network_image_mock

Licence: BSD-3-Clause license
Mock response for Image.network to help Flutter widget tests pass.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to network image mock

Retromock
Java library for mocking responses in a Retrofit service.
Stars: ✭ 48 (+118.18%)
Mutual labels:  mocking, testing-tools
Prig
Prig is a lightweight framework for test indirections in .NET Framework.
Stars: ✭ 106 (+381.82%)
Mutual labels:  mocking, testing-tools
mock-inspect
Mocks network requests and allows you to make assertions about how these requests happened. Supports auto-mocking of graphQL requests given a valid schema.
Stars: ✭ 19 (-13.64%)
Mutual labels:  mocking, testing-tools
MockDataGenerator
Generate mock data for POCO
Stars: ✭ 12 (-45.45%)
Mutual labels:  mocking, testing-tools
Hoverfly
Lightweight service virtualization/API simulation tool for developers and testers
Stars: ✭ 1,814 (+8145.45%)
Mutual labels:  mocking, testing-tools
php-test-generator
Generate test cases for existing PHP files
Stars: ✭ 47 (+113.64%)
Mutual labels:  mocking, testing-tools
Testdouble.js
A minimal test double library for TDD with JavaScript
Stars: ✭ 1,214 (+5418.18%)
Mutual labels:  mocking, testing-tools
laika
Log, test, intercept and modify Apollo Client's operations
Stars: ✭ 99 (+350%)
Mutual labels:  mocking, testing-tools
Mockbin
Mock, Test & Track HTTP Requests and Response for Microservices
Stars: ✭ 1,782 (+8000%)
Mutual labels:  mocking, testing-tools
Hoverfly Java
Java binding for Hoverfly
Stars: ✭ 130 (+490.91%)
Mutual labels:  mocking, testing-tools
Nsubstitute
A friendly substitute for .NET mocking libraries.
Stars: ✭ 1,646 (+7381.82%)
Mutual labels:  mocking, testing-tools
Mockito
Most popular Mocking framework for unit tests written in Java
Stars: ✭ 12,453 (+56504.55%)
Mutual labels:  mocking, testing-tools
Httpretty
Intercept HTTP requests at the Python socket level. Fakes the whole socket module
Stars: ✭ 1,930 (+8672.73%)
Mutual labels:  mocking, testing-tools
Mocktopus
Mocking framework for Rust
Stars: ✭ 179 (+713.64%)
Mutual labels:  mocking, testing-tools
toster
DSL framework for testing Android apps
Stars: ✭ 31 (+40.91%)
Mutual labels:  testing-tools
specter-php
JSON Mocking and Testing for PHP
Stars: ✭ 18 (-18.18%)
Mutual labels:  mocking
kmval
A Kubernetes Kustomize Manifest Validator
Stars: ✭ 24 (+9.09%)
Mutual labels:  testing-tools
react-jsdom
Render React components to actual DOM nodes in Node.js
Stars: ✭ 31 (+40.91%)
Mutual labels:  testing-tools
awesome-cypress
🎉 A curated list of awesome things related to Cypress
Stars: ✭ 274 (+1145.45%)
Mutual labels:  testing-tools
Deflector.NET
A library for intercepting all method calls at runtime in nearly any .NET application.
Stars: ✭ 80 (+263.64%)
Mutual labels:  mocking

Network Image Mock

Pub Version Lint & Test codecov.io Null safety No null safety GitHub Repo stars GitHub contributors GitHub code size in bytes GitHub

A utility for providing mocked response to Image.network in Flutter widget tests.

Introduction

Since you are here you probably already know that calling Image.network results in 400 response in Flutter widget tests. The reason for this is that default HTTP client in tests always return a 400.

So, what can we do about it? Instead of copying the whole code over and over again for mocking the HTTP client, I created this package. It is heavily inspired by roughike/image_test_utils, however that package is not being maintained despite multiple pull requests asking for bumping the mockito version and making the package usable again.

Installing

Null safety

This package should be installed under dev_dependencies with

dev_dependencies:
  network_image_mock: ^2.0.1

Without null safety (deprecated)

If you have legacy unmigrated code that does not use Null safety, install under dev_dependencies with

dev_dependencies:
  network_image_mock: 1.1.0

Example

The package is quite straightforward to use. All you have to do is include it in your test file and wrap widget testing functions that require proper Image.network response in mockNetworkImagesFor() function provided by this package. A full test example could look like this.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:network_image_mock/network_image_mock.dart';

Widget makeTestableWidget() => MaterialApp(home: Image.network(''));

void main() {
  testWidgets(
    'should properly mock Image.network and not crash',
    (WidgetTester tester) async {
      mockNetworkImagesFor(() => tester.pumpWidget(makeTestableWidget()));
    },
  );
}

This is actually an example taken from tests for this package.

Contributing

There is not much to contribute since the package serves its purpose, however, in chance of needing to bump or adjust some version, or any other suggestion for that matter, please read CONTRIBUTING.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].