Dynamic "test host" or bundle loader for iOS Unit Testing?
ios, sentestingkit, unit-testing, xcode
Solution
To do this you need to have a variable inside the build settings - which seems simple, but it's not. If you set an environment variable through a Pre- or Post- step in the application or test scheme, it does not seem as though it will be picked up here. The build settings, after all, happen before the build. Same is true of a preprocessor macro, though doing this using xcodebuild and passing in a custom option may work.
The only way I know of to do this is to use an xcconfig file. Create one and apply it to (at the least) your test target. The content should include something like this: `THINGUNDERTEST=FooBar`
Now in your project settings, wether in an xcconfig or the project file, set BUNDLER_LOADER to: `$(BUILT_PRODUCTS_DIR)/$(THINGUNDERTEST).app/$(THINGUNDERTEST)`
That will work. Now you can change THINGUNDERTEST through various means and get at least some dynamic behavior. This may work for you or may not, depending on your needs - but it probably only a starting point.
Problem
How do I make the test host/bundle loader dynamic based on the current scheme? Right now the value is set to: ``` $(BUILT_PRODUCTS_DIR)/MyApp1.app/MyApp1 ``` The problem is I have 4 apps in the workspace and I would like to use the same unit testing suite for all of them. How do I dynamically change the "MyApp1" part based on the current scheme? Is it an environment variable based during build? I tried setting it to things like $(PROJECT_NAME) but those seem to get the name of the test suite.