Skip to content

Document expected unit testing approach #1877

Open
@stuartmorgan-g

Description

@stuartmorgan-g

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions