mockito_code_generator 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 60

Mockito Code Generator #

A Dart package that generates code for the mockito library.

Pub #

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';

Cat _cat;

Dog _dog;

Dog _secondDog;

void main() {
  setUp(() {
    // Init mocks.

  test("Let's verify some behavior!", () {

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


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:

  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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

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).


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.39.5
build ^1.0.0 1.2.2
source_gen ^0.9.0 0.9.4+6 0.9.5
Transitive dependencies
args 1.6.0
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.2.10 1.3.3
front_end 0.1.24 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
kernel 0.3.24 0.3.29
logging 0.11.4
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.9.3
path 1.6.4
pedantic 1.9.0
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+14
yaml 2.2.0