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.
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.
- fake_cloud_firestore
Fake implementation of Cloud Firestore for unit testing.
87Compare - firebase_storage_mocks
Mocks for Firebase Storage to write unit tests.
82Compare - golden_screenshot
Utilities to automate screenshot generation using Flutter's golden tests.
76Compare - firebase_database_mocks
Mock library to write unit tests for Firebase Realtime Database.
77Compare
Works with
Packages commonly used together with mocktail: ones it builds on, ones built on it, and its own family.
- test_apimocktail depends on itThe user facing API for structuring Dart tests and checking expectations.
- matchermocktail depends on itSupport for specifying test expectations via an extensible Matcher class.
- bloc_testBuilt on mocktailA testing library that makes it easy to test blocs and cubits.
- mocktail_image_networkBuilt on mocktailMock Image.network in widget tests without real network calls
- bloc_presentation_testBuilt on mocktailA testing library for Blocs and Cubits utilizing BlocPresentationMixin.
- flutter_code_editorBuilt on mocktailA customizable code field widget supporting syntax highlighting and code folding.
- mocktailxBuilt on mocktailUtility functions for the mocktail library to increase productivity in tests.
- xdg_iconsBuilt on mocktailXDG theme icons for Flutter.