If you have been searching for a type of chocolate and ended up here stop reading as this type of chocolate isn’t going to be for your cup of tea.
You know and love Cocoapods and you would like to support testing with XCode using those beautiful time-savers within the pods in your UI test targets too.
There is only one problem. You paid a visit to the great Natasha’s blog and her solution although very elegant, didn’t work for you. Then you searched StackOverflow like nobody business and that left you more confused than with things to try. Finally, desperate and bleeding you ended up on this Github post. Which finally created in your mind an idea: I AM NOT CRAZY! This shit should actually work and it doesn’t.
News flash for you, no. You are not crazy. At least pod related crazy.
If you run UI Tests, at build time XCode builds and then Pod scripts do not copy to the test target build location the frameworks belonging to the main target that you want to include. Not only that, if you force it to do it, XCode still not be able to run the test complaining that an image is missing when you attempt to run the tests.
The reason is that XCode when runs those types of test uses another process that has the name of your test target plus an extension runner.app. Your dependencies (framework) must be copied under that location in order to allow the runner to find them and execute the test cases. Otherwise, the runner won’t find them causing some gibberish error in the console that doesn’t lead to any solution.
How did I work around it?
I created the following bash script that does just the following:
- Compose parts to create a path for source and destination
- Check if the framework folder exists
- If it does give a message in the build console and copy over the missing frameworks
To realize where they are going to be located, just right click on the runner and use show packages to see what’s inside.
That is the derived build folder that unless you have changed its default is here
I recommend that you follow Natasha’s elegant solution to create a podfile that is compliant and elegant, however, if you run XCode 7.3.x this fix is your sanity back when you run in UI test scenario that requires the runner. I searched everywhere I didn’t find it and I figured I could have saved you some Mario Bros lives.
I tested it with Cocoapods 1.1.0.rc.2 and it is sadly required otherwise your UI tests are just not going to work. Looking forward to the Cocoa gurus to fix this.
Fix - Recipe
- On the UI Test Target add a build phase script
- Copy this script there.
- Change within the script the app name. I didn’t find a variable to retrieve it automatically, so it’s hardcoded for now.
- Build and Run
- Enjoy, and if you make any improvement do let me know!
I hope that this saves you a lot of time and swearing when you put your UI tests together.
If you are dealing just with straight Unit Testing the issue that you are going to face is the same, however, the location where to drop the missing frameworks is different. In that case, use this gist.