Flutter ObjectBox – How to unittest?

Issue

I’m building my new Flutter app with objectBox as DB.
How can I write an unittest in Android Studio?

When I write a unittest that includes objectBox, at running the test I get following error message:

Failed to load "C:\Dev\flutter_rebuild\test\db_model_test.dart": Invalid argument(s): Failed to load dynamic library ‘lib/objectbox.dll’: 126

Solution

I found this on:
https://opensourcelibs.com/lib/objectbox-dart
It shows how to download an include the "objectbox.dll" to Windows so that the test can run in Android Studio.

  1. Dart standalone programs:

    • Install the packages pub get
    • Install objectbox-c system-wide:
      • macOS/Linux: execute the following command (answer Y when it asks about installing to /usr/lib)

        bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh)

        • macOS: if dart later complains that it cannot find the libobjectbox.dylib you probably have to unsign the dart binary (source: dart issue):

          sudo codesign --remove-signature $(which dart)

      • Windows: use "Git Bash" or similar to execute the following command

        bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh)

        Then copy the downloaded lib/objectbox.dll to C:\Windows\System32\ (requires admin privileges).

ObjectBox generates code binding code for classes you want stored based using build_runner. After you’ve defined your persisted entities (see below), run pub run build_runner build or flutter pub run build_runner build.

Answered By – F.M.

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *