Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document expected unit testing approach #1877

Open
stuartmorgan opened this issue Jan 9, 2025 · 0 comments
Open

Document expected unit testing approach #1877

stuartmorgan opened this issue Jan 9, 2025 · 0 comments

Comments

@stuartmorgan
Copy link

I attempted to write Dart unit tests of code that was converted from Pigeon to Obj-C ffigen, by using mockito to mock the top-level object created by the ffigen config, so that I was testing mock implementations of the native libraries. In my case, I needed to have the mock return an NSArray containing an NSString value. However, trying to do so results in:

Invalid argument(s): Couldn't resolve native function 'Dart_InitializeApiDL' in 'objective_c.framework/objective_c' : No asset with id 'objective_c.framework/objective_c' found. No available native assets. Attempted to fallback to process lookup. dlsym(RTLD_DEFAULT, Dart_InitializeApiDL): symbol not found.

dart:ffi                                                             Native._ffi_resolver_function
package:objective_c/src/c_bindings_generated.dart                    Dart_InitializeApiDL
package:objective_c/src/internal.dart 177:7                          _ensureDartAPI
package:objective_c/src/internal.dart 183:3                          _newFinalizableHandle
package:objective_c/src/internal.dart 202:23                         new _ObjCReference
package:objective_c/src/internal.dart 282:9                          new _ObjCObjectRef
package:objective_c/src/internal.dart 295:15                         new ObjCObjectBase
package:objective_c/src/objective_c_bindings_generated.dart 4881:9   new NSObject._
package:objective_c/src/objective_c_bindings_generated.dart 4890:14  new NSObject.castFromPointer
package:objective_c/src/objective_c_bindings_generated.dart 6383:15  new NSString._
package:objective_c/src/objective_c_bindings_generated.dart 6392:14  new NSString.castFromPointer
package:objective_c/src/objective_c_bindings_generated.dart 6480:21  NSString.stringWithCharacters_length_
package:objective_c/src/objective_c_bindings_generated.dart 6369:19  new NSString
test/path_provider_foundation_test.dart 252:35                       _arrayWithString
test/path_provider_foundation_test.dart 66:23                        main.<fn>.<fn>

I'm not surprised at this failure, because I'm familiar enough with the internals of some of the system, but I think most people would not understand why it fails, and would expect that mocking out system libraries was a reasonable thing to do. And even with the knowledge I do have, I'm not sure exactly what the fix is here (other than the obviously bad option of wrapping everything in a manually written conversion layer and mocking that; that would in fact be more work than just using Pigeon).

We need a clearly documented path for the use case of unit testing code written against native Obj-C libraries called via FFI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants