talira

mocktail

Mocks for Dart and Flutter tests without code generation

open sourceMITfree

mocktail is a mocking library for Dart and Flutter tests, inspired by Dart's mockito package. You create a mock by extending Mock and implementing the class, then stub calls with when(() => ...) and check them with verify, with null safety and no hand-written mocks or code generation step. The same repository has mocktail_image_network, which mocks Image.network in widget tests.

Problems it solves

  • mocking in Dart with mockito means running build_runner to generate mocks
  • mock a class in my Flutter unit tests without code generation
  • stub and verify method calls in Dart tests

Features

  • mock Dart classes in tests without code generation
  • stub calls and verify how often they were made
  • null-safe API inspired by mockito
  • mock Image.network in Flutter widget tests

Alternatives

The same job

These do what mocktail does.

  1. mockito Mock library for Dart, inspired by Java's Mockito

Compare mocktail with the top 3