DEV.co
Open-Source Testing · felangel

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.

Source: GitHub — github.com/felangel/mocktail
696
GitHub stars
87
Forks
Dart
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryfelangel/mocktail
Ownerfelangel
Primary languageDart
LicenseMIT — OSI-approved
Stars696
Forks87
Open issues20
Latest releasemocktail-image-network-v1.3.0 (2026-04-12)
Last updated2026-04-12
Sourcehttps://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.

Quickstart

Get the mocktail source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/felangel/mocktail.gitcd mocktail# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Unit testing Dart business logic

Mock dependencies in unit tests without requiring build_runner or code generation steps, ideal for backend services, data layers, and domain logic.

Flutter widget and integration testing

Mock Image.network and other Flutter APIs using mocktail_image_network to test UI components in isolation without network requests or external resource loading.

Rapid test development with null safety

Quickly scaffold test suites leveraging Dart's null safety type system; mocks are created at runtime, reducing test setup friction.

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.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

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.

Software development agency

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.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related 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?
No. Mocktail creates mocks at runtime via dynamic proxies, eliminating the build_runner step. Just add to pubspec and start mocking.
Can I mock Flutter widgets and Image.network directly?
Core mocktail handles most mocking; for Image.network specifically, use package:mocktail_image_network which is designed for that use case.
Is Mocktail compatible with my Flutter/Dart version?
Check pub.dev package page for SDK constraints. Generally supports modern Dart 2.x and Flutter stable/beta channels; requires Dart null safety.
Can I use Mocktail in production code?
Mocktail is intended for testing only; adding it to main dependencies (not dev_dependencies) is an anti-pattern and wastes bundle size. Always use dev_dependencies.

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.