objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
918 stars 116 forks source link

Missing tests examples for Flutter/Dart #585

Closed daniloapr closed 4 months ago

daniloapr commented 5 months ago

Is there an existing issue?

Use case

I would like to set up ObjectBox database for tests but couldn't find any examples in the docs or in the Github repository. Is there a way to test it?

Proposed solution

  1. Be able to setup test files like it's possible with other libraries such as Isar or SharedPreferences
  2. Add test examples in the official documentation and/or github repo examples.

Example for Isar:

Future<void> setUpIsarForTests() async {
  final binaryName = Platform.isWindows
      ? 'isar.dll'
      : Platform.isMacOS
          ? 'libisar.dylib'
          : 'libisar.so';

  final path = File('temp/$binaryName').absolute.path;

  await Isar.initializeIsarCore(
    download: true,
    libraries: {
      Abi.macosX64: path,
      Abi.macosArm64: path,
      Abi.linuxArm64: path,
      Abi.linuxX64: path,
      Abi.windowsX64: path,
    },
  );
}

Describe alternatives you've considered

greenrobot-team commented 5 months ago

We have not looked at unit testing in a Flutter package for a while, maybe we should.

But if you are fine with a Dart only test package, see the one in this repo for inspiration: https://github.com/objectbox/objectbox-dart/tree/main/objectbox_test

The add to project docs also have notes on how to download the C library required to run unit tests on your development machine.

Does that work for you?

daniloapr commented 5 months ago

Thanks for the response! Can you elaborate more on that?

What I need is to test a file in my Flutter project, which uses Object Box for data persisting, so I can ensure I'm performing the CRUD operations and complex queries properly. Would that work like that?

greenrobot-team commented 5 months ago

Looking at the Flutter unit testing docs, it appears using ObjectBox like in the test package of this repo should work. And then use flutter test instead of dart test. Again, have not tested that in a while.

As said, you might have to download the ObjectBox native library manually for the tests to execute. Look for the "To run unit tests on your machine" info box on the getting started page.

Or what are you missing?

github-actions[bot] commented 4 months ago

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.