mocktail
Mocktail is a Dart mocking library that simplifies writing unit and widget tests by providing an intuitive API for creating mock objects without code generation. It supports null safety and is inspired by the popular Mockito library.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | felangel/mocktail |
| Owner | felangel |
| Primary language | Dart |
| License | MIT — OSI-approved |
| Stars | 696 |
| Forks | 87 |
| Open issues | 20 |
| Latest release | mocktail-image-network-v1.3.0 (2026-04-12) |
| Last updated | 2026-04-12 |
| Source | https://github.com/felangel/mocktail |
What mocktail is
A pure-Dart mocking library offering null-safe mock creation through dynamic proxy patterns, eliminating boilerplate code generation. Provides both core mocking (package:mocktail) and Flutter-specific utilities (package:mocktail_image_network) for widget test scenarios.
Get the mocktail source
Clone the repository and explore it locally.
git clone https://github.com/felangel/mocktail.gitcd mocktail# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Requires Dart SDK compatibility; check package:mocktail pub.dev for minimum version constraints and Flutter stability.
- No build step means faster iteration but also means mock interfaces are not statically validated at compile time—API mismatches surface at runtime.
- Null safety is enforced; ensure all mocked methods and return types align with non-nullable type declarations.
- For Image.network mocking, must use package:mocktail_image_network alongside core mocktail; verify both packages are in pubspec.
- Test execution order and parallel test runs should be validated since mocks are created dynamically.
When to avoid it — and what to weigh
- Complex nested mock behavior required — If your test scenarios demand sophisticated mock interaction patterns or deep spy/verification chains, you may find manual verification more cumbersome than annotation-driven tools.
- Non-Dart/Flutter projects — Mocktail is Dart-specific and will not be useful for testing Java, Python, JavaScript, or other language codebases.
- Strict mock state isolation across test suites — If your project requires strict global mock registry cleanup or deterministic mock state between parallel test runs, runtime mock creation may introduce ordering dependencies.
- Performance-critical mock instantiation — Runtime proxy creation adds overhead per mock; projects testing thousands of lightweight objects per test suite may see measurable latency compared to pre-compiled stubs.
License & commercial use
MIT License. Permits commercial use, modification, and redistribution with attribution. No warranty provided.
MIT is a permissive OSI-approved license allowing commercial use in proprietary and closed-source applications. No license restrictions on deployment or revenue-generating products. Attribution in code comments is customary but not legally required by MIT terms.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Good |
| Assessment confidence | High |
Mocktail is test-only and not part of production runtime, reducing attack surface. Ensure test dependencies are pulled from trusted pub.dev registry. Runtime dynamic proxy creation (core mechanism) does not introduce unique exploits if used only in test environments. No cryptography, network, or privilege boundaries crossed. Standard Dart supply chain hygiene applies.
Alternatives to consider
mockito (Dart)
More mature, but requires code generation (build_runner); heavier setup but may offer more advanced verification patterns.
fake_async / FakeAsync
Simpler for time-based testing; does not replace general mocking but complements it for async/scheduler concerns.
mocktail for other languages (e.g., pytest-mock, Jest)
Equivalent mocking libraries exist for Python and JavaScript ecosystems; Mocktail is Dart-exclusive.
Build on mocktail with DEV.co software developers
Our Dart and Flutter experts can guide you through test architecture, mocking patterns, and CI/CD integration. Contact us to discuss your testing strategy.
Talk to DEV.coRelated on DEV.co
Explore the category and the services that help you build with it.
mocktail FAQ
Do I need to run code generation (build_runner) to use Mocktail?
Can I mock Flutter widgets and Image.network directly?
Is Mocktail compatible with my Flutter/Dart version?
Can I use Mocktail in production code?
Work with a software development agency
Adopting mocktail is usually one piece of a larger software development effort. As a software development agency, DEV.co provides software development services and web development expertise — pairing senior software developers and web developers with your team to design, build, and operate open-source testing software in production.
Need Help Integrating Mocktail into Your Dart Test Suite?
Our Dart and Flutter experts can guide you through test architecture, mocking patterns, and CI/CD integration. Contact us to discuss your testing strategy.