I’am tryng to run my unit test for this project, and it’s giving me this error message:
MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)
package:flutter/src/services/platform_channel.dart 332:7 MethodChannel._invokeMethod
LateInitializationError: Field 'todoBox' has not been initialized.
testunit_testtodo_unit_test.dart todoBox
testunit_testtodo_unit_test.dart 35:13 main.<fn>
How can I solve this error?
**
Here is the code:
**
import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hive/hive.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path_provider/path_provider.dart';
import 'package:todo_app/src/modules/adapter/todo_adapter.dart';
late TodoItemMock todoItemMock;
late Box<TodoItemMock> todoBox;
class TodoItemMock extends Mock implements TodoItem {}
class HiveConfig {
static start() async {
Directory dir = await getApplicationDocumentsDirectory();
Hive.init(dir.path);
}
}
void main() {
WidgetsFlutterBinding.ensureInitialized();
setUp(
() async {
await HiveConfig.start();
Hive.registerAdapter(TodoItemAdapter());
todoBox = await Hive.openBox<TodoItemMock>('todoBox');
},
);
tearDownAll(
() async {
await todoBox.close();
},
);
test('Get no results from the Box', () async {
expect(todoBox.get(0), completion(findsNothing));
});
}
I tried to make a Mock for the path provider but it’s not possible to call the class to mock it
New contributor
Luiz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.