Skip to content
pubscout

mocktail

1.0.5, released 7 months ago by felangel.dev

Dart mock library with null safety support and no manual mocks or code generation.

WASM-ready
$ flutter pub add mocktail
Source repository

What it does

Mocktail provides a simple API for creating mocks in Dart without the need for manual mocks or code generation. It uses closures to handle catching TypeError instances when stubbing and verifying return types.

AI-written summary of version 1.0.5, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to write unit tests with mocks in Dart or Flutter without running build_runner.
  • You want a mocking API inspired by mockito that supports null safety out of the box.

Skip it when

  • You prefer compile-time safe code-generated mocks.
  • You need to stub or verify extension methods directly.

Strengths

  • No code generation or manual mocks required.
  • Familiar API inspired by mockito.
  • Supports argument matchers and fallback values.

Weaknesses

  • Cannot directly stub or verify extension methods.
  • Requires registering fallback values for custom types when using argument matchers.

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
3

Not documented

import 'package:mocktail/mocktail.dart';

class Cat {
  String sound() => 'meow!';
}

class MockCat extends Mock implements Cat {}

void main() {
  final cat = MockCat();
  when(() => cat.sound()).thenReturn('meow');
  expect(cat.sound(), 'meow');
  verify(() => cat.sound()).called(1);
}

Alternatives

Packages that do the same job and could replace mocktail.

Works with

Packages commonly used together with mocktail: ones it builds on, ones built on it, and its own family.