This release is the first 3.0.0 release featuring the new Mockito 3 API. The README has been updated, and an upgrading-to-mockito-3 doc has been added to help users upgrade. Here's a quick rundown:
// Old API: when(obj.fn(typed(any)))... // New API: when(obj.fn(any))... // Old API: when(obj.fn(foo: typed(any, named: 'foo')))... // New API: when(obj.fn(foo: anyNamed('foo')))... // Old API: when(obj.fn(foo: typed(null, named: 'foo')))... // New API: when(obj.fn(foo: argThat(isNull, named: 'foo')))...
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:
>=2.0.0-dev.16.0
,dart --preview-dart-2
, or with Flutter Beta 3), andThis 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 print 0
, 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 the verify
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.
thenReturn
and thenAnswer
now support generics and infer the correct types from the when
call.mirrors.dart
).thenReturn
now throws an ArgumentError
if either a Future
or Stream
is provided. thenReturn
calls with futures and streams should be changed to thenAnswer
. See the README for more information.untilCalled
. See the README for documentation.capture*
calls outside of a verify*
call no longer capture arguments.mock.methodWithListArgs([1,2,3].map((e) => e*2))
(note the Iterable
argument) will no longer match the following stub: when(mock.methodWithListArgs([42])).thenReturn(7);
.when
, verify
, verifyNever
, resetMockitoState
.throwOnMissingStub
, resetMockitoState
.verify
.<2.0.0-dev.infinity
to support Dart 2.0 development testing.test/example/iss
.InvocationMatcher
instead of the old matcher.throwOnMissingStub
back to invoking Object.noSuchMethod
:throwsNoSuchMethodError
if you want to catch it.throwOnMissingStub
method to the API.mockito_no_mirrors.dart
spy
and any dart:mirrors
based API from mockito.dart
. Users may import as package:mockito/mirrors.dart
going forward.mockito_no_mirrors.dart
; replace with mockito.dart
.>=1.21.0 <2.0.0
to use generic methods.thenThrow
method to the API.thenAnswer
in the README.typed
API that is compatible with Dart Dev Compiler; documented in README.md.spy
code into a private source file. Now package:mockito/mockito.dart
includes this reflection-based API, and a new package:mockito/mockito_no_mirrors.dart
doesn't require mirrors.argThat(identical(arg))
.