dart-lang / mockito

Mockito-inspired mock library for Dart
https://pub.dev/packages/mockito
Apache License 2.0
632 stars 162 forks source link

Example doesn't work on last dart version & flutter sdk #670

Closed iamguid closed 1 year ago

iamguid commented 1 year ago

I can't run your example in new project

I just create a new project using flutter create test and then install dependencies, then add file from example and name it cat.dart and put it to lib folder

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

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

// Real class
class Cat {
  String sound() => "Meow";
  bool eatFood(String food, {bool? hungry}) => true;
  Future<void> chew() async => print("Chewing...");
  int walk(List<String> places) => 7;
  void sleep() {}
  void hunt(String place, String prey) {}
  int lives = 9;
}

void main() {
  // Create mock object.
  var cat = MockCat();
}

Dart SDK version: 3.0.5 (stable) (Mon Jun 12 18:31:49 2023 +0000) on "macos_arm64" Flutter 3.10.5 • channel stable • https://github.com/flutter/flutter.git Framework • revision 796c8ef792 (3 weeks ago) • 2023-06-13 15:51:02 -0700 Engine • revision 45f6e00911 Tools • Dart 3.0.5 • DevTools 2.23.1

pubspec.yaml

name: test
description: A new Flutter project.
publish_to: 'none'
version: 1.0.0+1

environment:
  sdk: '>=3.0.5 <4.0.0'
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  mockito: ^5.4.2
  build_runner: ^2.4.6

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
flutter:
  uses-material-design: true

The result after run dart run build_runner build is

Building package executable... (4.3s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 158ms
[INFO] Reading cached asset graph completed, took 34ms
[INFO] Checking for updates since last build completed, took 577ms
[INFO] Running build completed, took 7ms
[INFO] Caching finalized dependency graph completed, took 30ms
[INFO] Succeeded after 43ms with 0 outputs (0 actions)

0 outputs and 0 actions Without errors or some logs.

yanok commented 1 year ago

Please read a NOTE close to the end of this subsection, is your added cat.dart file under test/?

iamguid commented 1 year ago

Sorry, I didn't see it in the documentation, important thing. Thank you for the help!

Judimax commented 10 months ago

Greetings I think the fact that files need to be in test needs to be heavily highlihted