Dynamic "test host" or bundle loader for iOS Unit Testing?
Asked Answered
D

1

6

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.

Dissimilation answered 15/7, 2013 at 16:56 Comment(1)
I'm faced to the same problem. I have several targets in which I want to perform the same target test. Obviously that too much too handle for Xcode. My solution was to add a script in order to change the XCodeProject then target the right app.Virescent
M
7

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.

Manipular answered 24/7, 2013 at 21:21 Comment(2)
In my case, my test target requires a host application. So BUNDLER_LOADER reads the value from TEST_HOST. So I set $(BUILT_PRODUCTS_DIR)/$(THINGUNDERTEST).app/$(THINGUNDERTEST) to TEST_HOST instead.Onomastics
This works indeed. In my case I was sending dynamically resolved value of THINGUNDERTEST to the app as xctool command-line argument. Same should work for xcodebuild. E.g. xcodebuild <other_params> THINUNDERTEST=MyApp testPrecipitous

© 2022 - 2024 — McMap. All rights reserved.