dart-lang / mockito

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

Error The included part 'mocks.dart' must have a part-of directive. #723

Closed bilalrabibi closed 7 months ago

bilalrabibi commented 7 months ago

I am getting error when i run the following command

dart run build_runner clean && dart run build_runner build --delete-conflicting-outputs

Error is The included part 'file:///Users/b/Desktop/apps/new_app1/test/test_bird.mocks.dart' must have a part-of directive.

where test/test_bird.dart file is below and test_bird.mocks.dart is generated successfully.

import 'package:mockito/annotations.dart';
import 'package:new_app1/bird.dart';
part 'test_bird.mocks.dart';
@GenerateMocks([Bird])
void main() {}
Generated File// Mocks generated by Mockito 5.4.3 from annotations // in new_app1/test/test_bird.dart. // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:mockito/mockito.dart' as _i1; import 'package:new_app1/bird.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references // ignore_for_file: deprecated_member_use // ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class /// A class which mocks [Bird]. /// /// See the documentation for Mockito's code generation for more information. class MockBird extends _i1.Mock implements _i2.Bird { MockBird() { _i1.throwOnMissingStub(this); } @override int get count => (super.noSuchMethod( Invocation.getter(#count), returnValue: 0, ) as int); @override set count(int? _count) => super.noSuchMethod( Invocation.setter( #count, _count, ), returnValueForMissingStub: null, ); @override void incrementCounter() => super.noSuchMethod( Invocation.method( #incrementCounter, [], ), returnValueForMissingStub: null, ); @override void fly() => super.noSuchMethod( Invocation.method( #fly, [], ), returnValueForMissingStub: null, ); @override void prey() => super.noSuchMethod( Invocation.method( #prey, [], ), returnValueForMissingStub: null, ); @override void drink() => super.noSuchMethod( Invocation.method( #drink, [], ), returnValueForMissingStub: null, ); }

pubs.yaml file

name: new_app1
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
  sdk: '>=3.1.4 <4.0.0'
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
 dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
  build_runner: ^2.4.6
  mockito: ^5.4.3
flutter:
  uses-material-design: true
Flutter Doctor [✓] Flutter (Channel stable, 3.13.8, on macOS 14.1.1 23B81 darwin-arm64, locale en-GB) • Flutter version 3.13.8 on channel stable at /Users/bilalrabbi/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 6c4930c4ac (5 weeks ago), 2023-10-18 10:57:55 -0500 • Engine revision 767d8c75e8 • Dart version 3.1.4 • DevTools version 2.25.0 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/bilalrabbi/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A240d • CocoaPods version 1.13.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.4) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin version 76.1.4 • Dart plugin version 232.10072.19 [✓] VS Code (version 1.83.1) • VS Code at /Users/bilalrabbi/Downloads/Visual Studio Code.app/Contents • Flutter extension version 3.76.0 [✓] Connected device (5 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 14 (API 34) (emulator) • iPhone (mobile) • 00008030-001004D80146802E • ios • iOS 17.1.1 21B91 • iPhone 15 Pro (mobile) • E38B776E-A099-445D-B344-DFC39087A23B • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.1.1 23B81 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.159 [✓] Network resources • All expected network resources are available.
srawlins commented 7 months ago

Thanks for filing an issue. Definitely don't write part 'test_bird.mocks.dart'; into your test. The generated file is not a part.