iOS Application Test static library initialization

848 Views Asked by At

I'm trying to write tests for an iOS app with a legacy C++ library dependency. The legacy library has initialization routines and static variables that must be run/set once per app cycle.

I've created a test target that is working correctly. My test target is set to use my app as a Test Host through the Bundle Loader. This launches the iOS app and then uses [SenTestCase invoke test] to run the tests. Given this setup, I am hoping to let the app initialize the library and let the tests run in a "library already initialized" state. This seems to fit the Apple Application Test paradigm. However, the legacy libraries' static variables initialized during app launch are NULL when the tests are run. There is no user code that would reset the variables.

I am expecting my Application Tests to be able to access my app's static variables. Is there something I can configure to allow this? Am I missing something?


To clarify, the troublesome static variables are in the linked c++ library. The app and unit tests do not seem to share the same application scope.

1

There are 1 best solutions below

1
On

I had a similar problem, but with an Obj-C static library. Singletons were created twice (once in the app and once in the test bundle). Their pointers are also in static memory.

The problem was that I was linking the library into the test bundle target.

I fixed it by removing the library from "Link Binary With Libraries" list. Then I also needed to change a build setting of the static library: I had to set "Symbols Hidden by Default" to NO.