netsells / hive_test

Initialize a temporary Hive database for testing
MIT License
4 stars 1 forks source link

Hive stuck inside testWidgets #2

Open jesusmartinoza opened 2 years ago

jesusmartinoza commented 2 years ago

Hello, for some reasons using Hive inside testWidgets method doesn't work.

// 📦 Package imports:
import 'package:flutter_test/flutter_test.dart';
import 'package:hive/hive.dart';

// 🌎 Project imports:
import 'package:hive_test/hive_test.dart';

void main() {
  testWidgets('initializing, using, and closing a test Hive works', (WidgetTester tester) async {
    print('Enters here');
    await setUpTestHive();
    print("Doesn't enters here");

    final box = await Hive.openBox<int>('testBox');

    await box.add(1);
    await box.clear();

    await tearDownTestHive();
  });
}

Changing testWidgets -> to test works.

Any help appreciated. And thanks for this lib <3

mhmzdev commented 3 months ago

Same here, not working in testWidgets

julianryorex commented 1 week ago

Perhaps try adding it in the setup/teardown?

setUp(() async {
    await setUpTestHive();
  });

  tearDown(() async {
    await tearDownTestHive();
  });