Skip to content

Upgrading mockito 4 to 5

Breaking4.1.4 → 5.8.1Breaking8Platform7Deprecated2New21Changed41Fixed39Other11

BreakingUpgrade verdict

8 breaking changes and 7 platform requirement changes.

  • Two old options for controlling missing stubs are gone, so code using them must be updated.
  • Three old helper functions for type-checked arguments are gone, so code using them must be updated.
  • Unstubbed methods on nice mocks now return a descriptive String instead of an empty one, so tests that expected an empty String may fail.
  • Mock generation now only looks in the test directory by default. If your mocks are generated from files elsewhere, you must list those files explicitly.
Top 5 of 17 that need code or config changes

Dart SDK requirement changed in 5.4.6: >=2.7.0 <3.0.0 → ^3.7.0.

Adds path ^1.9.0.

Breaking8
Removes deprecated returnNullOnMissingStub and OnMissingStub.returnNull MockSpec options.
returnNullOnMissingStubOnMissingStub.returnNullMockSpec
Removes the deprecated typed, typedArgThat, and typedCaptureThat APIs.
typedtypedArgThattypedCaptureThat
Changes the default String returned by nice mocks' unstubbed methods to include useful info, which may break tests expecting an empty String.
Defaults generate_for to test/**, so mocks for libraries outside test/ are no longer generated unless configured.
generate_for
Republishes retracted 4.1.0 as a major version; the new BuildStep member librarySourceSink breaks packages that implement BuildStep.
BuildSteplibrarySourceSinkbuild_runner
Changes the error thrown when a method is called with no matching stub from NoSuchMethodError to MissingStubError.
NoSuchMethodErrorMissingStubError
Generating mocks for non-JS interop extension types is now an error; mock the representation type and cast instead.
Changes Mock.noSuchMethod's optional positional parameter "returnValue" to a named parameter and adds a second named parameter.
Mock.noSuchMethodreturnValue
Platform7
Requires Dart SDK ^3.7.0.
Requires Dart SDK ^3.7.0.
Requires Dart SDK ^3.6.0.
Requires dart_style '>=2.3.7 <4.0.0' so the current Dart language version can be passed to DartFormatter.
dart_styleDartFormatter
Requires Dart >=3.1.0.
Requires Dart >= 2.19.0.
Requires Dart >= 2.17.0.
Deprecated2
Deprecates the mixingIn argument to MockSpec; best practice is to avoid concrete implementations in classes extending Mock.
MockSpecmixingInMock
Deprecates the MockSpec returnNullOnMissingStub parameter in favor of onMissingStub.
MockSpecreturnNullOnMissingStubonMissingStub

Generated by DepDelta from published Dart source. Not mixed with prose notes.

  • removed: field MockSpec.returnNullOnMissingStub: final bool
  • changed: ctor MockSpec({Symbol as, this.returnNullOnMissingStub = …}) → ctor MockSpec({ Symbol? as, @Deprecated( 'Avoid adding concrete implementation to mock classes. ' 'Use a manual implementation of the class without `Mock`', ) List<Type> mixingIn = …, this.unsupportedMembers = …, this.fallbackGenerators = …, this.onMissingStub, })
  • changed: field MockSpec.mockName: final Symbol → field MockSpec.mockName: final Symbol?
  • added: class GenerateNiceMocks
  • added: ctor GenerateNiceMocks(this.mocks)
  • added: enum OnMissingStub
  • added: field GenerateNiceMocks.mocks: final List<MockSpec>
  • added: field MockSpec.fallbackGenerators: final Map<Symbol, Function>
  • added: field MockSpec.mixins: final List<Type>
  • added: field MockSpec.onMissingStub: final OnMissingStub?
  • added: field MockSpec.unsupportedMembers: final Set<Symbol>
  • added: member OnMissingStub.returnDefault
  • added: member OnMissingStub.throwException
  • removed: ctor VerificationResult(int callCount)
  • removed: function typed<T>(ArgMatcher matcher, {String named}): Null
  • removed: function typedArgThat(Matcher matcher, {String named}): Null
  • removed: function typedCaptureThat(Matcher matcher, {String named}): Null
  • removed: get verifyInOrder: _InOrderVerification
  • changed: class Mock → class Mock: mixin
  • changed: function argThat(Matcher matcher, {String named}): Null → function argThat(Matcher matcher, {String? named}): Null
  • changed: function captureThat(Matcher matcher, {String named}): Null → function captureThat(Matcher matcher, {String? named}): Null
  • changed: function clearInteractions(var mock): void → function clearInteractions(Object? mock): void
  • changed: function named<T extends Mock>(T mock, {String name, int hashCode}): T → function named<T extends Mock>(T mock, {String? name, int? hashCode}): T
  • changed: function reset(var mock): void → function reset(Object? mock): void
  • changed: function throwOnMissingStub( Mock mock, { void Function(Invocation) exceptionBuilder, }): void → function throwOnMissingStub( Mock mock, { void Function(Invocation)? exceptionBuilder, }): void
  • changed: function verifyNoMoreInteractions(var mock): void → function verifyNoMoreInteractions(Object? mock): void
  • changed: function verifyZeroInteractions(var mock): void → function verifyZeroInteractions(Object? mock): void
  • changed: method Mock.noSuchMethod(Invocation invocation, [Object returnValue]): dynamic → method Mock.noSuchMethod( Invocation invocation, { Object? returnValue, Object? returnValueForMissingStub = …, }): dynamic
  • changed: method Mock.operator ==(other): bool → method Mock.operator ==(Object other): bool
  • changed: method PostExpectation.thenThrow(throwable): void → method PostExpectation.thenThrow(Object throwable): void
  • added: class FakeFunctionUsedError extends Error
  • added: class FakeUsedError extends Error
  • added: class MissingDummyValueError
  • added: class MissingStubError extends Error
  • added: class SmartFake
  • added: ctor FakeFunctionUsedError( this.parentInvocation, this.receiver, this.createdStackTrace, )
  • added: ctor FakeUsedError( this.parentInvocation, this.invocation, this.receiver, this.createdStackTrace, )
  • added: ctor MissingDummyValueError(this.type)
  • added: ctor MissingStubError(this.invocation, this.receiver)
  • added: ctor SmartFake(this._parent, this._parentInvocation)
  • added: extension ListOfVerificationResult on List<VerificationResult>
  • added: field FakeFunctionUsedError.createdStackTrace: final StackTrace
  • added: field FakeFunctionUsedError.parentInvocation: final Invocation
  • added: field FakeFunctionUsedError.receiver: final Object
  • added: field FakeUsedError.createdStackTrace: final StackTrace
  • added: field FakeUsedError.invocation: final Invocation
  • added: field FakeUsedError.parentInvocation: final Invocation
  • added: field FakeUsedError.receiver: final Object
  • added: field MissingDummyValueError.type: final Type
  • added: field MissingStubError.invocation: final Invocation
  • added: field MissingStubError.receiver: final Object
  • added: function provideDummy<T>(T dummy): void
  • added: function provideDummyBuilder<T>(DummyBuilder<T> dummyBuilder): void
  • added: get ListOfVerificationResult.captured: List<List<dynamic>>
  • added: method FakeFunctionUsedError.toString(): String
  • added: method FakeUsedError.toString(): String
  • added: method MissingDummyValueError.toString(): String
  • added: method MissingStubError.toString(): String
  • added: method PostExpectation.thenReturnInOrder(List<T> expects): void
  • added: method SmartFake.noSuchMethod(Invocation invocation): dynamic
  • added: method SmartFake.operator ==(Object? other): bool
  • added: method SmartFake.toString(): String
  • added: static field Mock.deferToDefaultResponse: const