Ui testing framework


My notes on setting up a UI-testing-framework

⚠️️ This is now outdated ⚠️️ See the bottom section regarding doing this with SPM. ⚠️️

This is for carthage, but can easily be done with SPM

100% Carthage .framework support

  • Add the UITestSugar.framework to the Test-project folder 👉 drag it to the frameworks folder. 👉 select the UITestTarget
  • In The UITestTarget 👉 build-phases 👉 click plus-button 👉 Copy files 👉 drag the .framework file into that panel 👉 make sure destination is set to framework.
  • In the UITestSugar project: Add $(PLATFORM_DIR)/Developer/Library/Frameworks to the in “Build settings” 👉 “framework search paths”
  • Then add the magic build settings setting that I have not been able to identify. What I do is i clone this project: https://github.com/shindyu/XCTestExtensions And then clean it up and use it as a base. You can also rename the project etc. To find the magic setting, we can diff the .proj file. But I was not able to find the missing piece as of now.
  • ⚠️️ (Optional-step) ⚠️️ Use Cartfile.private file instead of Cartfile because these dependencies will only be needed in this local project. And does not need to be visible for other dependencies higher up the hierarchy

Add UITestSugar / TestRunner to projects:

  • Add github "eonist/TestRunner" "master" and github "eonist/UITestSugar" "master" to Cartfile
  • Terminal: carthage update --platform ios
  • In The UITestTarget 👉 build-phases 👉 click plus-button 👉 Copy files 👉 drag the .framework file into that panel 👉 make sure destination is set to framework.
  • Add import UITestSugar and import TestRunner to the top of your .swift files and hit cmd + U to run the UITest

Nesting UI-Testing frameworks

  • Use the same methodology as Non-nested UI-testing frameworks.

Partial carthage solution: (for the sake of reference, don’t use this)

  • Add XCTest.framework in the linked framework and libraries list in General.
  • You have to add Framework search-path: $(PLATFORM_DIR)/Developer/Library/Frameworks in Build settings
  • import MyTestFramework
  • Limitations: ⚠️️ I have not been able to load this kind of framework as a pure .framework through carthage, seems the .framework cant find the correct paths somehow. But you can load the src code from carthage and then build the .framework from that src code. Its a bit more hassle to manage src files, but with some more digging I think its possible to figure out the path issue

Resources:

Gotchas:

This is much easier for SPM (Update):

  • Add package to the UITest target only, not the app target. Either via xcode packagemanager or manually.
  • Add linkerSettings: [.linkedFramework("XCTest")] to the package. See https://github.com/eonist/UITestSugar for example