mockito_builder 0.2.3 copy "mockito_builder: ^0.2.3" to clipboard
mockito_builder: ^0.2.3 copied to clipboard

discontinued

Generate Flutter `mockito` mocks and mock method with a list of types to be mocked.

Pub Package

Important Notice #

This package has been renamed to mockor. Please migrate to the new package.

Generate Flutter mockito mocks and mock method with a list of types to be mocked.

Getting Started #

Add the dependency #

Add the mockito_builder to your dev_dependencies. And mockito_builder_annotations to dependencies.

dependencies:
  mockito_builder_annotations: ^0.2.2
dev_dependencies:
  mockito_builder: ^0.2.2

Add a mocker.dart file in your test folder and a mock method with a @GenerateMocker annotation. Don't forget to import mockito here. #


import 'package:mockito_builder/mockito_builder.dart';
import 'domain/navigation/navigation_service.dart';
import 'domain/usecases/register_user_use_case.dart';
///make sure to import the mockito package because the generated code depends on it.
import 'package:mockito/mockito.dart';

part 'mocker.g.dart';

///this will generate a `mocker.g.dart` file.
///specify the classes that should be mocked. 
@GenerateMocker([RegisterUserUseCase, NavigationService])
///define a method without any paramters and one type paramter. 
///an implementation of the method will be generated with a _$ prefix.
T mock<T>() => _$mock<T>();

To use the generated mocks, simply import and call the defined mock function #

import '../../mocker.dart';
import 'domain/navigation/navigation_service.dart';
import 'domain/usecases/register_user_use_case.dart';

void main() {
  RegisterUserUseCase registerUserUseCase;
  NavigationService navigationService;
  RegisterViewModel viewModel;

  setUp(() {
    registerUserUseCase = mock();
    navigationService = mock();
    viewModel = RegisterViewModelImpl(registerUserUseCase, navigationService);
  });
  
  ...
  
}

for more info check out the example module.

3
likes
40
pub points
0%
popularity

Publisher

verified publisherrmdy.be

Generate Flutter `mockito` mocks and mock method with a list of types to be mocked.

Homepage

License

GPL-3.0 (license)

Dependencies

analyzer, build, code_builder, dart_style, flutter, mockito_builder_annotations, source_gen

More

Packages that depend on mockito_builder