1

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.

HatAndBeard
  • 1,416
  • 3
  • 18
  • 31
  • Do you have other unit tests besides this one that can access your app? – Jon Reid Aug 19 '12 at 02:50
  • I can access the app fine in all my other tests. It is only the static variables in the c++ library that cause problems. – HatAndBeard Aug 20 '12 at 14:49
  • 1
    I'm running into this as well. I believe the problem is that there are 2 versions of your static variable being created; 1 in your test binary and 1 in your application binary. To clarify, I believe this is an issue with all static variables, not just c++. – Tylerc230 Nov 09 '12 at 19:05

1 Answers1

4

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.

Martijn Thé
  • 4,674
  • 3
  • 29
  • 42
  • 1
    Oh boy you saved my ass! I was linking a static lib (.a) twice, hence the static var for singleton where there twice, even with dispatch_once... – malaba Jun 28 '13 at 16:27