mockito
A mock framework inspired by Mockito with APIs for Fakes, Mocks, behavior verification, and stubbing.
5.8.1
2.3M downloads/mo
#240 most downloaded on pub.dev
dart-lang/build
What this package is like to depend on
Last release 18 days ago
06 Aug 2026
Release timing varies
gaps range from 2 weeks to 12 months
Most releases are documented
notes for 55 of 64 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
83 releases · first in 2014
8 releases in the last 12 months
see the full history below
Release timeline
83 releases · Jul 2014 to Aug 2026Releases
latest 60 of 83-
5.8.106 Aug 2026Release notes
Open source →- Cast dummy values for extension types to the extension type so they satisfy
static type checking in generic return types likeFuture<ExtensionType>.
#4590 - Use canonical asset path in generated header comments so symlink paths are
excluded.
#4545 - Deterministically select library to import when multiple libraries export the
same type.
#4549 - Prefer importing public entrypoints over
/src/implementation libraries
when multiple libraries export the same type.
#4551 - Throw
InvalidMockitoAnnotationExceptionwith a clear message when
@GenerateMockscustomMocksor@GenerateNiceMocksmocksis not a list
literal, instead of crashing with a type cast exception.
#4428 - Remove redundant per-class
// ignore: must_be_immutablecomment to prevent
duplicate_ignorewarnings.
#4588 - Clarify in
README.mdthat generated.mocks.dartfilenames are based on the
source file name.
#4599 - Suppress
experimental_member_usewarnings in generated mock files.
#4602 - Document missing stub behavior for
voidandFuture<void>.
Release notes
Open source →- Cast dummy values for extension types to the extension type so they satisfy
static type checking in generic return types like
Future<ExtensionType>. #4590 - Use canonical asset path in generated header comments so symlink paths are excluded. #4545
- Deterministically select library to import when multiple libraries export the same type. #4549
- Prefer importing public entrypoints over
/src/implementation libraries when multiple libraries export the same type. #4551 - Throw
InvalidMockitoAnnotationExceptionwith a clear message when@GenerateMockscustomMocksor@GenerateNiceMocksmocksis not a list literal, instead of crashing with a type cast exception. #4428 - Remove redundant per-class
// ignore: must_be_immutablecomment to preventduplicate_ignorewarnings. #4588 - Clarify in
README.mdthat generated.mocks.dartfilenames are based on the source file name. #4599 - Suppress
experimental_member_usewarnings in generated mock files. #4602 - Document missing stub behavior for
voidandFuture<void>.
- Cast dummy values for extension types to the extension type so they satisfy
-
5.8.031 Jul 2026Release notes
Open source →- Add support for JS interop extension type mock generation to mockito.
- It is now an error to generate mocks for non-JS interop extension types.
Instead, mock the representation type and cast to the extension type where
needed. - Remove Mockito version number from generated output.
- Allow
analyzer14.0.0.
Release notes
Open source →- Add support for JS interop extension type mock generation to mockito.
- It is now an error to generate mocks for non-JS interop extension types. Instead, mock the representation type and cast to the extension type where needed.
- Remove Mockito version number from generated output.
- Allow
analyzer14.0.0.
-
5.7.019 May 2026Release notes
Open source →- Handle JS interop extension types and provide dummy values for them. #4498
-
5.6.530 Apr 2026 -
5.6.424 Mar 2026 -
5.6.312 Jan 2026 -
5.6.121 Nov 2025 -
5.5.104 Sep 2025Release notes
Open source →- Require
analyzer: ^8.1.0. - Allow
source_gen: '>=3.0.0 <5.0.0'. - Allow
build: '>=3.0.0 <5.0.0'.
- Require
-
5.5.021 Jul 2025 -
5.5.0-dev08 Jul 2025 pre-release -
5.4.621 Apr 2025Release notes
Open source →- When formatting a generated mocks library, use the language version of the library with the mockito annotation.
-
5.4.518 Dec 2024Release notes
Open source →- Ignore "must_be_immutable" warning in generated files. Mocks cannot be made immutable anyway, but this way users aren't prevented from using generated mocks altogether.
- Require Dart SDK ^3.6.0.
- Require
analyzer: '>=6.9.0 <8.0.0'. - Require
dart_style: '>=2.3.7 <4.0.0', so that the current Dart language version can be passed toDartFormatter. - Require
source_gen: ">=1.4.0 <3.0.0". - Add support for extension types.
- Add topics to
pubspec.yaml. - Fix a bug where type aliases in type arguments were not correctly resolved.
- Fix a bug where record types were not correctly resolved.
-
5.4.414 Dec 2023 -
5.4.316 Nov 2023Release notes
Open source →- Require analyzer 5.12.0, allow analyzer version 6.x;
- Add example of writing a class to mock function objects.
- Add support for the
build_extensionsbuild.yaml option - Require Dart >=3.1.0.
- Potentially breaking Changed default
Stringvalue returned by nice mocks' unstubbed method to include some useful info. This could break the tests that relied on getting an emptyStringfrom unstubbed methods. - Remove deprecated
returnNullOnMissingStubandOnMissingStub.returnNullMockSpecoptions.
-
5.4.210 Jun 2023Release notes
Open source →- Require code_builder 4.5.0.
- Add support for records.
- Fixed the bug with missing imports for unused type alias arguments.
-
5.4.123 May 2023Release notes
Open source →- Deprecate the
mixingInargument toMockSpec. Best practice is to avoid any concrete implementation in classes which extendMock. - Fixed generation for clashing type variable names.
- Require Dart >= 2.19.0.
- Require analyzer 5.11.0.
- Fail to generate mocks of
sealed/base/finalclasses. - Add new
thenReturnInOrdermethod to mock multiple calls to a single method in order. - Add
provideDummy/provideDummyBuilderfunctions for users to supply dummy values to Mockito, to cover cases where codegen can't create one. - Allow generating mocks for classes with methods/getters returning non-nullable unknown types.
- Deprecate the
-
5.4.024 Mar 2023Release notes
Open source →- Fix nice mocks generation in mixed mode (generated code is pre null-safety, while mocked class is null-safe).
- Support typedef-aliased classes in
@GenerateMocksand@GenerateNiceMocks - Breaking Default
generate_fortotest/**. Projects that are generating mocks for libraries outside of thetest/directory should add an explicitgenerate_forargument to include files with mock generating annotations. - Require Dart >= 2.17.0.
- Require analyzer 5.2.0.
-
5.3.222 Sep 2022 -
5.3.114 Sep 2022Release notes
Open source →- Fix analyzer and code_builder dependencies.
- Reference
@GenerateNiceMocksin documentation. - Allow generating a mock class which includes overriding members with private
types in their signature. Such members cannot be stubbed with mockito, and
will only be generated when specified in MockSpec
unsupportedMembers. - Include
requiredkeyword in functions used as default return values.
-
5.3.028 Jul 2022Release notes
Open source →- Introduce a new
MockSpecparameter,onMissingStub, which allows specifying three actions to take when a real call is made to a mock method with no matching stub. The two existing behaviors are the default behavior of throwing an exception, and the legacy behavior of returningnull. A new behavior is also introduced: returning a legal default value. With this behavior, legal default values are returned for any given type. - Deprecate the
MockSpecreturnNullOnMissingStubparameter in favor of the newonMissingStubparameter. - Introduce a new
@GenerateNiceMocksannotation, that uses the new "return a legal value" behavior for missing stubs. - Add
SmartFakeclass to be used as a return values for unstubbed methods. It remembers where it was created and throws a descriptive error in case the fake is later used. - Include
requiredkeyword in function types to match overridden function types.
- Introduce a new
-
5.2.017 May 2022Release notes
Open source →- Fix generation of methods with return type of
FutureOr<T>for generic, potentially nullableT. - Support
@GenerateMocksannotations onimportandexportdirectives. - Support analyzer 4.x.
- Fix generation of methods with return type of
-
5.1.011 Feb 2022Release notes
Open source →- In creating mocks for a pre-null-safe library, opt out of null safety in the generated code.
- Properly generate method overrides for methods with covariant parameters. #4533
- Correctly generate a
toStringoverride method for pre-null safe libraries, for which the class-to-mock implementstoStringwith additional parameters. - Improve messaging in a MissingStubError, directing to the docs for MockSpec.
- Fix incorrect error when trying to mock a method with a parameter with inner function types (like in type arguments) which are potentially non-nullable. #4511
- Allow fallback generators to be applied for getters.
- Support generating a mock class for a class with members with non-nullable
unknown return types via a new parameter on
MockSpeccalledunsupportedMembers. See [NULL_SAFETY_README][] for details.
-
5.0.1720 Dec 2021 -
5.0.1614 Sep 2021Release notes
Open source →- Fix type reference for nested, imported types found in type arguments on a custom class-to-mock. #4508
- Bump minimum analyzer dependency to version 2.1.0.
- Ignore
camel_case_typeslint in generated code.
-
5.0.1523 Aug 2021Release notes
Open source →- Fix an issue generating the correct parameter default value given a constructor which redirects to a constructor declared in a separate library. #4861
-
5.0.1406 Aug 2021 -
5.0.1330 Jul 2021Release notes
Open source →- Implement methods which have been overridden in the mixin hierarchy properly. Previously, mixins were being applied in the wrong order, which could skip over one method that overrides another with a different signature. #4859
-
5.0.1221 Jul 2021Release notes
Open source →- Use an empty list with a correct type argument for a fallback value for a method which returns Iterable. #4853
- When selecting the library that should be imported in order to reference a type, prefer a library which exports the library in which the type is declared. This avoids some confusion with conditional exports. #4691
- Properly reference types in overridden
toStringimplementations. #4687 - Override
toStringin a Fake implementation when the class-to-be-faked has a superclass which overridestoStringwith additional parameters. #4640 - Support analyzer 2.x.
-
5.0.1115 Jul 2021Release notes
Open source →- Allow two mocks of the same class (with different type arguments) to be specified with different fallback generators.
- Allow fallback generators on super types of a mocked class.
- Avoid
inference_failure_on_instance_creationerrors in generated code. - Ignore
implementation_importslint in generated code. - Support methods with
FunctionandFuture<Function>return types.
-
5.0.1007 Jun 2021Release notes
Open source →- Generate a proper mock class when the mocked class overrides
toString,hashCode, oroperator==. #4672 - Override
toStringimplementation on generated Fakes in order to match the signature of an overriding method which adds optional parameters. #4640 Properly type methods in a generated mock class which comes from a "custom mock" annotation referencing an implicit type. Given a method which references type variables defined on their enclosing class (for example,Tinclass Foo<T>), mockito will now correctly referenceTin generated code. #4674
- Generate a proper mock class when the mocked class overrides
-
5.0.925 May 2021Release notes
Open source →- Mock classes now implement a type's nested type arguments properly. #4667
- Mock classes now implement API from a class's interface(s) (in addition to superclasses and mix ins). Thanks @markgravity. #404
- A MockSpec passed into a
@GenerateMocksannotation'scustomMockslist can now specify "fallback generators." These are functions which can be used to generate fake responses that mockito's code generation needs in order to return a value for a method with a generic return type. See NULL_SAFETY_README for details.
-
5.0.819 May 2021Release notes
Open source →- Migrate Mockito codegen to null safety.
- Support mocking methods with typed_data List return types.
- Support mocking methods with return types declared in private SDK libraries
(such as HttpClient and WebSocket, declared in
dart:_http). - Do not generate a fake for a class which is only used as a nullable type in a Future. #4666
-
5.0.728 Apr 2021 -
5.0.627 Apr 2021 -
5.0.520 Apr 2021 -
5.0.412 Apr 2021 -
5.0.325 Mar 2021 -
5.0.217 Mar 2021 -
5.0.112 Mar 2021Release notes
Open source →- Update to the latest test_api.
- Fix mock generation of type which has a supertype which mixes in a mixin.
- Fix mock generation of method which returns a non-nullable generic function type.
-
5.0.023 Feb 2021Release notes
Open source →verifyInOrdernow returns aList<VerificationResult>which stores arguments which were captured in a call toverifiyInOrder.- Breaking change: Remove the public constructor for
VerificationResult. - Doesn't allow
verifybeen used inside theverifyInOrder.
-
5.0.0-nullsafety.704 Feb 2021 pre-releaseRelease notes
Open source →- Fix generation of duplicate mock getters and setters from inherited classes.
-
5.0.0-nullsafety.603 Feb 2021 pre-releaseRelease notes
Open source →- Fix generation of method with a parameter with a default value which includes a top-level function.
- Migrate example code to null safety.
- Breaking change: Change the error which is thrown if a method is called and no method stub was found, from NoSuchMethodError to MissingStubError.
- Breaking change:
Mock.noSuchMethod's optional positional parameter, "returnValue" is changed to a named parameter, and a second named parameter is added. Any manual mocks which callMock.noSuchMethodwith a second positional argument will need to instead use the named parameter. - Allow real calls to mock methods which return
void(like setters) orFuture<void>, even if unstubbed.
-
5.0.0-nullsafety.522 Jan 2021 pre-release -
5.0.0-nullsafety.418 Jan 2021 pre-release -
5.0.0-nullsafety.314 Jan 2021 pre-releaseRelease notes
Open source →- Improve static analysis of generated code.
- Make implicit casts from dynamic in getters explicit.
-
5.0.0-nullsafety.212 Jan 2021 pre-releaseRelease notes
Open source →- Fix issue with generated code which references a class declared in a part (#4604).
-
5.0.0-nullsafety.130 Dec 2020 pre-releaseRelease notes
Open source →- Fix an issue with generated mocks overriding methods from Object, such as
operator ==(#4603). - Fix an issue with relative imports in generated mocks.
- Fix an issue with generated mocks overriding methods from Object, such as
-
5.0.0-nullsafety.022 Dec 2020 pre-releaseRelease notes
Open source →- Migrate the core libraries and tests to null safety. The builder at
lib/src/builder.dartopts out of null safety. - Add
httpback todev_dependencies. It's used by the example. - Remove deprecated
typed,typedArgThat, andtypedCaptureThatAPIs.
- Migrate the core libraries and tests to null safety. The builder at
-
4.1.426 Jan 2021Nothing published for this version
-
4.1.321 Oct 2020Release notes
Open source →- Bug fix: fix race condition when a new daemon immediately starts after
shutdown. - Put lock and config files under
.dart_toolin the workspace by default.
Make them user private. AdddaemonSharedPathto keep support for other
locations. - Use a token for websocket authentication.
- Require Dart 3.11.0.
Release notes
Open source →- Allow using analyzer 0.40.
throwOnMissingStubaccepts an optional argument,exceptionBuilder, which will be called to build and throw a custom exception when a missing stub is called.
- Bug fix: fix race condition when a new daemon immediately starts after
-
4.1.228 Aug 2020Release notes
Open source →- Introduce experimental code-generated mocks. This is primarily to support the new "Non-nullable by default" (NNBD) type system coming soon to Dart.
- Add an optional second parameter to
Mock.noSuchMethod. This may break clients who use the Mock class in unconventional ways, such as overridingnoSuchMethodon a class which extends Mock. To fix, or prepare such code, add a second parameter to such overridingnoSuchMethoddeclaration. - Increase minimum Dart SDK to
2.7.0. - Remove Fake class; export identical Fake class from the test_api package.
-
4.1.104 Sep 2019Release notes
Open source →- Mark the unexported and accidentally public
setDefaultResponseas deprecated. - Mark the not useful, and not generally used,
namedfunction as deprecated. - Produce a meaningful error message if an argument matcher is used outside of
stubbing (
when) or verification (verifyanduntilCalled).
- Mark the unexported and accidentally public
-
4.1.1+111 Mar 2021Nothing published for this version
-
4.1.031 May 2019Release notes
Open source →- Add a
Fakeclass for implementing a subset of a class API as overrides without misusing theMockclass.
- Add a
-
4.0.006 Nov 2018 -
3.0.205 Nov 2018Release notes
Open source →- Rollback the test_api part of the 3.0.1 release. This was breaking tests that use Flutter's current test tools, and will instead be released as part of Mockito 4.0.0.
-
3.0.101 Nov 2018 -
3.0.024 Jul 2018Release notes
Open source →-
Deprecate the
typedAPI; instead of wrapping other Mockito API calls, likeany,argThat,captureAny, andcaptureArgThat, with a call totyped, the regular API calls are to be used by themselves. PassinganyandcaptureAnyas named arguments must be replaced withanyNamed()andcaptureAnyNamed, respectively. PassingargThatandcaptureThatas named arguments must include thenamedparameter. -
Introduce a backward-and-forward compatible API to help users migrate to Mockito 3. See more details in the upgrading-to-mockito-3 doc.
-
thenReturnnow throws anArgumentErrorif either aFutureorStreamis provided.thenReturncalls with futures and streams should be changed tothenAnswer. See the README for more information. -
Support stubbing of void methods in Dart 2.
-
thenReturnandthenAnswernow support generics and infer the correct types from thewhencall. -
Completely remove the mirrors implementation of Mockito (
mirrors.dart). -
Fix compatibility with new noSuchMethod Forwarding feature of Dart 2. This is thankfully a mostly backwards-compatible change. This means that this version of Mockito should continue to work:
- with Dart
>=2.0.0-dev.16.0, - with Dart 2 runtime semantics (i.e. with
dart --preview-dart-2, or with Flutter Beta 3), and - with the new noSuchMethod Forwarding feature, when it lands in CFE, and when it lands in DDC.
This change, when combined with noSuchMethod Forwarding, will break a few code paths which do not seem to be frequently used. Two examples:
class A { int fn(int a, [int b]) => 7; } class MockA extends Mock implements A {} var a = new MockA(); when(a.fn(typed(any), typed(any))).thenReturn(0); print(a.fn(1));This used to print
null, because only one argument was passed, which did not match the two-argument stub. Now it will print0, as the real call contains a value for both the required argument, and the optional argument.a.fn(1); a.fn(2, 3); print(verify(a.fn(typed(captureAny), typed(captureAny))).captured);This used to print
[2, 3], because only the second call matched theverifycall. Now, it will print[1, null, 2, 3], as both real calls contain a value for both the required argument, and the optional argument. - with Dart
-
Upgrade package dependencies.
-
Throw an exception when attempting to stub a method on a Mock object that already exists.
-
-
3.0.0-beta16 May 2018 pre-releaseNothing published for this version
-
3.0.0-beta+122 Jun 2018 pre-releaseNothing published for this version