mockito_code_generator 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new48

Mockito Code Generator #

A Dart package that generates code for the mockito library.

Pub #

https://pub.dev/packages/mockito_code_generator

BuildMock Annotation #

Variables annotated with BuildMock will trigger code generation.

How it works #

By adding the annotation to a variable that you want to mock:

part 'my_test.g.dart';

@BuildMock()
Cat _cat;

@BuildMock()
Dog _dog;

@BuildMock()
Dog _secondDog;

void main() {
  setUp(() {
    // Init mocks.
    _initMocks();
  });

  test("Let's verify some behavior!", () {
    _cat.sound();
    _dog.sound();
    _secondDog.sound();
    verify(_cat.sound());
    verify(_dog.sound());
    verify(_secondDog.sound());
  });

And running

pub run build_runner build --delete-conflicting-outputs

The generator will create the my_test.g.dart file for you:

part of 'my_test.dart';

class CatMock extends Mock implements Cat {}
class DogMock extends Mock implements Dog {}

void _initMocks() {
  _cat = CatMock();
  _dog = DogMock();
  _secondDog = DogMock();
}

It gets all annotated fields and create their corresponding Mock classes. It also creates a _initMocks method that initializes the annotated fields;

By using the generator you don't need to manually create the Mock classes.

Examples #

  • Cat test - an example of how to use BuildMock annotation

Maintainers #

0.1.0 #

Initial Version of the library.

  • Includes the ability to generate mock code from a @BuildMock annotation

example/README.md

Mock Generator Sample #

A Flutter project that shows how Mockito Code Generator works.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mockito_code_generator: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mockito_code_generator/annotations.dart';
import 'package:mockito_code_generator/builder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
1
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Oct 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: other

Platform components identified in package: build, io, mirrors.

Health issues and suggestions

Document public APIs. (-1 points)

5 out of 5 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/mockito_generator.dart. (-0.50 points)

Analysis of lib/src/mockito_generator.dart reported 1 hint:

line 11 col 9: Use isNotEmpty instead of length

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (analyzer).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
analyzer >=0.32.4 <=0.38.2 0.38.2 0.38.5
build ^1.0.0 1.2.0
source_gen ^0.9.0 0.9.4+5
Transitive dependencies
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.2.10 1.3.1
front_end 0.1.24 0.1.27
glob 1.1.7
html 0.14.0+3
kernel 0.3.24 0.3.27
logging 0.11.3+2
meta 1.1.7
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0