CheckOps home

Tools directory

M

CheckOps

mocktail

mocktail is an MIT-licensed Dart mocking library, inspired by mockito, with null-safety support and no manual mocks or code generation, widely used in Flutter tests.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

mocktail is a Dart mocking library created by Felix Angelov (also known for the bloc library). Its README describes it as simplifying mocking with null-safety support and no manual mocks or code generation. Since Dart’s null safety made the original mockito package rely on code generation, mocktail became a popular alternative because you simply extend Mock and implement your interface.

Stubs use a callback syntax: when(() => repo.fetchUser(any())).thenAnswer((_) async => user) or .thenReturn(...) and .thenThrow(...). Verification uses verify(() => repo.save(any())).called(1) and verifyNever(...). Argument matchers include any() and captureAny(), and registerFallbackValue provides default values for custom types used with matchers. The repository also contains mocktail_image_network for mocking network images in widget tests. It works with package:test and flutter_test.

The source code is at felangel/mocktail on GitHub under the MIT licence, with about 702 stars; the most recent commit was on 22 October 2026.

Because mocks are plain Dart classes, they work in pure Dart packages as well as Flutter apps.

Features

  1. No code generation: Extend Mock and implement the interface.
  2. Null-safe: Designed for sound null safety.
  3. Callback syntax: Type-safe when and verify.
  4. Flutter-friendly: Works with flutter_test and image mocking.

Pros

  1. Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
  2. Actively maintained: The repository had commits as recent as 22 October 2026.

Cons

  1. Fallback values: Custom types need registerFallbackValue for matchers.
  2. Dart only: Specific to Dart and Flutter.
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class MockUserRepo extends Mock implements UserRepo {}

void main() {
  test('loads profile', () async {
    final repo = MockUserRepo();
    when(() => repo.fetchUser(any())).thenAnswer((_) async => User('Ana'));

    final profile = await ProfileService(repo).load('42');

    expect(profile.name, 'Ana');
    verify(() => repo.fetchUser('42')).called(1);
  });
}

Resources:

Pricing

mocktail is free and open source under the MIT licence.

  1. Flutter and Dart developers wanting mocks without code generation.
  2. Bloc and state-management users testing repositories and services.

Conclusion

mocktail is the simplest way to mock in null-safe Dart, and a staple of Flutter test suites.

Alternatives

Other tools on CheckOps that cover similar ground. Open a page, or compare one with mocktail side by side.