GenerateNiceMocks class

An annotation to direct Mockito to generate mock classes.

During code generation, Mockito will generate a Mock{Type} extends Mock class for each class to be mocked, in {name}.mocks.dart, where {name} is the basename of the file in which @GenerateNiceMocks is used.

For example, if @GenerateNiceMocks([MockSpec<Foo>()]) is found at the top-level of a Dart library, foo_test.dart, then Mockito will generate class MockFoo extends Mock implements Foo in a new library, foo_test.mocks.dart.

If the class-to-mock is generic, then the mock will be identically generic. For example, given the class class Foo<T, U>, Mockito will generate class MockFoo<T, U> extends Mock implements Foo<T, U>.

@GenerateNiceMocks is different from @GenerateMocks in two ways:

  • only MockSpecs are allowed in the argument list
  • generated mocks won't throw on unstubbed method calls by default, instead some value appropriate for the target type will be returned.

Constructors

GenerateNiceMocks(List<MockSpec> mocks)
const

Properties

hashCode int
The hash code for this object.
no setterinherited
mocks List<MockSpec>
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited