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.
Latest public signals
Last updated: 16 November 2026 (weekly freshness scan: commit dates corrected).
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 to the default branch was on 12 April 2026.
Because mocks are plain Dart classes, they work in pure Dart packages as well as Flutter apps.
Features
- No code generation: Extend
Mockand implement the interface. - Null-safe: Designed for sound null safety.
- Callback syntax: Type-safe
whenandverify. - Flutter-friendly: Works with flutter_test and image mocking.
Pros
- Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
- Actively maintained: The default branch had commits as recent as 12 April 2026.
Cons
- Fallback values: Custom types need
registerFallbackValuefor matchers. - Dart only: Specific to Dart and Flutter.
Usage and Links (Example)
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.
Recommended for?
- Flutter and Dart developers wanting mocks without code generation.
- 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.
FFlutter Test (flutter_test)flutter_test is Flutter's official testing package and flutter test command for unit and widget tests, with WidgetTester, finders, matchers, golden-file tests and coverage.Compare with mocktail
PPatrolPatrol is LeanCode's Apache-2.0, Flutter-first E2E UI testing framework that extends integration_test with native automation (permissions, notifications, WebViews, device settings), custom finders, test isolation and sharding.Compare with mocktail
FFlutter integration_testintegration_test is Flutter's official package for end-to-end tests that run a full app on physical devices, emulators or Firebase Test Lab, using flutter_test-style APIs and the flutter drive or flutter test commands.Compare with mocktail
MMockitoMockito is the MIT-licensed, most popular mocking framework for Java, used to create mocks, stubs and spies with a clean API; Mockito 5 uses the inline mock maker by default and requires Java 11.Compare with mocktail
MMockKMockK is an Apache-2.0 mocking library built for Kotlin, supporting final classes, objects, coroutines, extension functions and top-level functions with a concise DSL.Compare with mocktail
MMoxMox is an Apache-2.0 Elixir library from Dashbit for defining concurrent, behaviour-based mocks that follow the "mocks as explicit contracts" principles and work with async tests.Compare with mocktail