flutter-rust-ffi icon indicating copy to clipboard operation
flutter-rust-ffi copied to clipboard

How to write test for the rust functions

Open hanwencheng opened this issue 5 years ago • 1 comments

I tried to write some test, under both ./test and ./example/test

but it comes with error:

Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, my_function_name): symbol not found)
  dart:ffi                                                          DynamicLibrary.lookup

Though it can be called in the application.

I tried to add some delay for loading the test, but still failed, probabaly some extra setting is required.

It should more related to ffi package, discussed it there: https://github.com/dart-lang/ffi/issues/39

hanwencheng avatar Apr 23 '20 21:04 hanwencheng

I'm not sure the environment you are trying to run this on, but testing will only work if you mix apples with apples.

The makefile will compile native bindings for Android and iOS. If you try to load these libraries on Linux or Mac, they are not going to run, since your desktop operating system runs another architecture and another platform.

The current test file already explains this. If you run the test using flutter test on your computer, the Dart code will only work if you try to load a Linux/MacOS library, which is not yet available.

Now that Flutter desktop is supporting MacOS and Linux, this becomes a viable option, though.

brickpop avatar Sep 06 '20 21:09 brickpop