@GenerateMocks and @GenerateNiceMocksgenerate_for to test/**. Projects that are generating mocks for libraries outside of the test/ directory should add an explicit generate_for argument to include files with mock generating annotations.@GenerateNiceMocks in documentation.unsupportedMembers.required keyword in functions used as default return values.MockSpec parameter, 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 returning null. A new behavior is also introduced: returning a legal default value. With this behavior, legal default values are returned for any given type.MockSpec returnNullOnMissingStub parameter in favor of the new onMissingStub parameter.@GenerateNiceMocks annotation, that uses the new “return a legal value” behavior for missing stubs.SmartFake class 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.required keyword in function types to match overridden function types.FutureOr<T> for generic, potentially nullable T.@GenerateMocks annotations on import and export directives.toString override method for pre-null safe libraries, for which the class-to-mock implements toString with additional parameters.MockSpec called unsupportedMembers. See NULL_SAFETY_README for details.toString unless the class-to-mock implements toString with additional parameters. #461camel_case_types lint in generated code.toString implementations. #438toString in a Fake implementation when the class-to-be-faked has a superclass which overrides toString with additional parameters. #371inference_failure_on_instance_creation errors in generated code.implementation_imports lint in generated code.Function and Future<Function> return types.toString, hashCode, or operator==. #420toString implementation on generated Fakes in order to match the signature of an overriding method which adds optional parameters. #371 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, T in class Foo<T>), mockito will now correctly reference T in generated code. #422@GenerateMocks annotation‘s customMocks list 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.dart:_http).prefer_const_constructors and avoid_redundant_argument_values lint rule violations in generated code.test_api.Future return value. #380verifyInOrder now returns a List<VerificationResult> which stores arguments which were captured in a call to verifiyInOrder.VerificationResult.verify been used inside the verifyInOrder.Mock.noSuchMethod's optional positional parameter, “returnValue” is changed to a named parameter, and a second named parameter is added. Any manual mocks which call Mock.noSuchMethod with a second positional argument will need to instead use the named parameter.void (like setters) or Future<void>, even if unstubbed.noSuchMethod invocation of setters in generated mocks.@override.operator == (#306).lib/src/builder.dart opts out of null safety.http back to dev_dependencies. It's used by the example.typed, typedArgThat, and typedCaptureThat APIs.throwOnMissingStub accepts an optional argument, exceptionBuilder, which will be called to build and throw a custom exception when a missing stub is called.Mock.noSuchMethod. This may break clients who use the Mock class in unconventional ways, such as overriding noSuchMethod on a class which extends Mock. To fix, or prepare such code, add a second parameter to such overriding noSuchMethod declaration.2.7.0.setDefaultResponse as deprecated.named function as deprecated.when) or verification (verify and untilCalled).Fake class for implementing a subset of a class API as overrides without misusing the Mock 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.
Deprecate the typed API; instead of wrapping other Mockito API calls, like any, argThat, captureAny, and captureArgThat, with a call to typed, the regular API calls are to be used by themselves. Passing any and captureAny as named arguments must be replaced with anyNamed() and captureAnyNamed, respectively. Passing argThat and captureThat as named arguments must include the named 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 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.
Support stubbing of void methods in Dart 2.
thenReturn and thenAnswer now support generics and infer the correct types from the when 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:
>=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.
Upgrade package dependencies.
Throw an exception when attempting to stub a method on a Mock object that already exists.
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.dartspy 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)).