// the find
felangel/mocktail
A mock library for Dart inspired by mockito
A Dart mocking library modelled on mockito's API, without the code generation. You declare `class MockFoo extends Mock implements Foo {}` and stub or verify calls with `when` and `verify`. It is aimed at Flutter and Dart developers who want mocks in unit and widget tests without running build_runner after every interface change.
- No build step. Mocks are plain classes, so there is no generated file to keep in sync, and `any()` is generic over the parameter type, so stubs are type-checked where they are written.
- The mockito_compat test folder covers verify, captureAny, until-called and invocation matching. That is the cheapest evidence that moving an existing mockito suite is a realistic path.
- The core is a small set of files under lib/src (argument matchers, invocation matching, recorded calls). It is short enough to read in one sitting before you depend on it.
- The companion package mocktail_image_network applies the same approach to Flutter's Image.network in widget tests and ships with an example app and tests, which shows the library working on a framework class and not only on toy interfaces.
- Custom types passed to `any()` need `registerFallbackValue` in setUpAll. If you forget it, the failure shows up at runtime in the test that uses the matcher, not when you write the code. This is the main sharp edge of dropping codegen.
- Because the mock extends Mock and implements the interface, adding a method to the interface does not break compilation of the mock. The new method falls through to noSuchMethod and fails only when a test calls it.
- Unstubbed calls return null. A method with a non-nullable return type therefore throws a type error at the call site, not a message naming the missing `when`, which makes under-stubbed tests slower to debug.