Hive: Issue with Hive + Flutter Driver for Integration Tests

Created on 21 Sep 2019  路  3Comments  路  Source: hivedb/hive

Hi,

First off, thanks for this fantastic package! I just replaced both Shared Preferences and Secure Storage with Hive and am thrilled to have a single solution. Well done!

The issue in question is happening during my integration testing (using flutter_driver), which at this point is just a simple test to login to my app. Prior to Hive, this worked fine. After Hive, it now breaks with a seemingly unrelated error. Because of the unhelpful error, it took me a while to track it down.

Steps to Reproduce
I've created a minimal reproduction in this repo: https://github.com/jamesdixon/hive_flutter_driver_issue

  1. Clone the repo
  2. Run flutter drive --target=test_driver/run_app.dart

Result (on Emulators):
DriverError: Error in Flutter application: Uncaught extension error while executing tap: 'package:flutter_driver/src/extension/extension.dart': Failed assertion: line 193 pos 14: 'WidgetsBinding.instance.isRootWidgetAttached || !command.requiresRootWidgetAttached': No root widget is attached; have you remembered to call runApp()?

Result (on physical iPhone):
[VERBOSE-2:shell.cc(178)] Dart Error: Unhandled exception: FileSystemException: writeFrom failed, path = '' (OS Error: Input/output error, errno = 5)

Next, comment out line 12 of main.dart where we use Hive to open a box.

Run the test command again and the result will be that all tests pass on both emulators and devices.

I'm not sure if this is a Flutter Driver error or a Hive error but figured I'd take a shot and post it here first :)

Version

  • Platform: Mac
  • Flutter version: 1.9.1 hotfix 2
  • Hive version: 1.0.0
bug

All 3 comments

Thanks that you took the time to file this issue.
I think the problem is that you open a box in the main method.

Running the app will be delayed for a split second and Flutter Driver does not seem to like that.

You should use a FutureBuilder to open a box. Here you can find an example.

I agree that Flutter Driver doesn't like it but FutureBuilder isn't an option for me as in my real application, I initialize a service layer at startup and one of those services is a LocalStorageService that's using Hive.

Theoretically, since main is async, I would expect Flutter Driver to respect that and wait for it to finish initializing but it appears that isn't the case. I'll file an issue in the main Flutter repo and report back.

Thanks!

@leisim I went ahead an opened an issue in the Flutter repo as I don't think this is Hive-specific after doing more testing.

https://github.com/flutter/flutter/issues/41029

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hopheylalal picture Hopheylalal  路  4Comments

ninest picture ninest  路  3Comments

kaboc picture kaboc  路  3Comments

cachapa picture cachapa  路  4Comments

yaymalaga picture yaymalaga  路  4Comments