mockito 5.0.13 mockito: ^5.0.13 copied to clipboard
A mock framework inspired by Mockito with APIs for Fakes, Mocks, behavior verification, and stubbing.
5.0.13 #
- 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. #456
5.0.12 #
- Use an empty list with a correct type argument for a fallback value for a method which returns Iterable. #445
- 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. #443
- Properly reference types in overridden
toString
implementations. #438 - Override
toString
in a Fake implementation when the class-to-be-faked has a superclass which overridestoString
with additional parameters. #371 - Support analyzer 2.0.0
5.0.11 #
- 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_creation
errors in generated code. - Ignore
implementation_imports
lint in generated code. - Support methods with
Function
andFuture<Function>
return types.
5.0.10 #
- Generate a proper mock class when the mocked class overrides
toString
,hashCode
, oroperator==
. #420 - Override
toString
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
inclass Foo<T>
), mockito will now correctly referenceT
in generated code. #422
5.0.9 #
- Mock classes now implement a type's nested type arguments properly. #410
- 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
@GenerateMocks
annotation'scustomMocks
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.
5.0.8 #
- 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. #409
5.0.7 #
5.0.6 #
- Support the 0.4.x releases of
test_api
.
5.0.5 #
- Support 4.x releases of code_builder.
5.0.4 #
5.0.3 #
- Support 1.x releases of source_gen.
5.0.2 #
- Support the latest build packages and dart_style.
5.0.1 #
- 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.0 #
verifyInOrder
now returns aList<VerificationResult>
which stores arguments which were captured in a call toverifiyInOrder
.- Breaking change: Remove the public constructor for
VerificationResult
. - Doesn't allow
verify
been used inside theverifyInOrder
.
5.0.0-nullsafety.7 #
- Fix generation of duplicate mock getters and setters from inherited classes.
5.0.0-nullsafety.6 #
- 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.noSuchMethod
with 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.5 #
- Fix
noSuchMethod
invocation of setters in generated mocks.
5.0.0-nullsafety.4 #
- Annotate overridden getters and setters with
@override
.
5.0.0-nullsafety.3 #
- Improve static analysis of generated code.
- Make implicit casts from dynamic in getters explicit.
5.0.0-nullsafety.2 #
- Fix issue with generated code which references a class declared in a part (#310).
5.0.0-nullsafety.1 #
- Fix an issue with generated mocks overriding methods from Object, such as
operator ==
(#306). - Fix an issue with relative imports in generated mocks.
5.0.0-nullsafety.0 #
- Migrate the core libraries and tests to null safety. The builder at
lib/src/builder.dart
opts out of null safety. - Add
http
back todev_dependencies
. It's used by the example. - Remove deprecated
typed
,typedArgThat
, andtypedCaptureThat
APIs.
4.1.3 #
- Allow using analyzer 0.40.
throwOnMissingStub
accepts an optional argument,exceptionBuilder
, which will be called to build and throw a custom exception when a missing stub is called.
4.1.2 #
- 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.
4.1.1 #
- 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
).
4.1.0 #
- Add a
Fake
class for implementing a subset of a class API as overrides without misusing theMock
class.
4.0.0 #
3.0.2 #
- 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.1 #
3.0.0 #
-
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.
2.2.0 #
- 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);
.
2.1.0 #
- 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
.
2.0.2 #
- 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.
2.0.1 #
- Add a new
throwOnMissingStub
method to the API.
2.0.0 #
- Removed
mockito_no_mirrors.dart
2.0.0-dev #
- 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.
1.0.1 #
- Add a new
thenThrow
method to the API. - Document
thenAnswer
in the README. - Add more dartdoc.
1.0.0 #
- Add a new
typed
API that is compatible with Dart Dev Compiler; documented in README.md.
0.11.1 #
- 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.
0.11.0 #
- 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))
.
0.10.0 #
- Added support for spy.
0.9.0 #
- Migrate from the unittest package to use the new test package.
- Format code using dartformat