Skip to content

@generateMocks documentation usage confusing #826

@emileswain

Description

@emileswain

mockito: ^5.5.0

Problem

I'm a little confused as to how @GenerateNiceMocks is supposed to work.

In the docs

// Annotation which generates the cat.mocks.dart library and the MockCat class.
@GenerateNiceMocks([MockSpec<Cat>()])
import 'cat.mocks.dart';

The docs suggest that if i have GenerateMocks above the import it till generate that file for me, in the case below i'm led to believe that it should generate me.mocks.dart

Short Example

[test/test_one.dart]

@GenerateNiceMocks([MockSpec<Me>()])
import 'me.mocks.dart';

It doesn't. it generates the class test_one.mocks.dart. i.e. it creates the mock for Me in the file test_one.mocks.dart

My Full example.

[test/test_one.dart]

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';

@GenerateNiceMocks([MockSpec<Me>()])
import 'me.mocks.dart';   <-- not generated because Generate creates test_one.mocks.dart

/// Test mock class

// Real class
class Me {
  final int property;
  late final String constructorProperty;

  Me({required this.property})
  {
    constructorProperty = "test";
  }

  bool action() {
    throw Exception("action not set");
  }

  String get myValue => constructorProperty;
}

Solution

I'm not sure if this is an issue with my setup, understanding of whats intented, flutter, or something else.

Clarrity in the documentation (i.e. showing what the name of the files are) would go a long way in helping undersand whats expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions