- 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 overridingnoSuchMethod
on a class which extends Mock. To fix, or prepare such code, add a second parameter to such overridingnoSuchMethod
declaration. - Increase minimum Dart SDK to
2.7.0
. - Remove Fake class; export identical Fake class from the test_api package.
- Mark the unexported and accidentally public
setDefaultResponse
as deprecated. - Mark the not useful, and not generally used,
named
function as deprecated. - Produce a meaningful error message if an argument matcher is used outside of
stubbing (
when
) or verification (verify
anduntilCalled
).
- Add a
Fake
class for implementing a subset of a class API as overrides without misusing theMock
class.
-
Replace the dependency on the test package with a dependency on the new test_api package. This dramatically reduces mockito's transitive dependencies.
This bump can result in runtime errors when coupled with a version of the test package older than 1.4.0.
- 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.
- Replace the dependency on the test package with a dependency on the new test_api package. This dramatically reduces mockito's transitive dependencies.
- Internal improvements to tests and examples.
-
Deprecate the
typed
API; 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. Passingany
andcaptureAny
as named arguments must be replaced withanyNamed()
andcaptureAnyNamed
, respectively. PassingargThat
andcaptureThat
as named arguments must include thenamed
parameter. -
Introduce a backward-and-forward compatible API to help users migrate to Mockito 3. See more details in the upgrading-to-mockito-3 doc.
-
thenReturn
now throws anArgumentError
if either aFuture
orStream
is provided.thenReturn
calls with futures and streams should be changed tothenAnswer
. See the README for more information. -
Support stubbing of void methods in Dart 2.
-
thenReturn
andthenAnswer
now support generics and infer the correct types from thewhen
call. -
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 theverify
call. 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.
- Add new feature to wait for an interaction:
untilCalled
. See the README for documentation. capture*
calls outside of averify*
call no longer capture arguments.- Some collections require stricter argument matching. For example, a stub like:
mock.methodWithListArgs([1,2,3].map((e) => e*2))
(note theIterable
argument) will no longer match the following stub:when(mock.methodWithListArgs([42])).thenReturn(7);
.
- Add documentation for
when
,verify
,verifyNever
,resetMockitoState
. - Expose
throwOnMissingStub
,resetMockitoState
. - Improve failure message for
verify
. - SDK version ceiling bumped to
<2.0.0-dev.infinity
to support Dart 2.0 development testing. - Add a Mockito + test package example at
test/example/iss
.
- Start using the new
InvocationMatcher
instead of the old matcher. - Change
throwOnMissingStub
back to invokingObject.noSuchMethod
:- It was never documented what the thrown type should be expected as.
- You can now just rely on
throwsNoSuchMethodError
if you want to catch it.
- Add a new
throwOnMissingStub
method to the API.
- Removed
mockito_no_mirrors.dart
- Remove export of
spy
and anydart:mirrors
based API frommockito.dart
. Users may import aspackage:mockito/mirrors.dart
going forward. - Deprecated
mockito_no_mirrors.dart
; replace withmockito.dart
. - Require Dart SDK
>=1.21.0 <2.0.0
to use generic methods.
- Add a new
thenThrow
method to the API. - Document
thenAnswer
in the README. - Add more dartdoc.
- Add a new
typed
API that is compatible with Dart Dev Compiler; documented in README.md.
- Move the reflection-based
spy
code into a private source file. Nowpackage:mockito/mockito.dart
includes this reflection-based API, and a newpackage:mockito/mockito_no_mirrors.dart
doesn't require mirrors.
- Equality matcher used by default to simplify matching collections as arguments. Should be non-breaking change in most cases, otherwise consider using
argThat(identical(arg))
.
- Added support for spy.
- Migrate from the unittest package to use the new test package.
- Format code using dartformat