[iOS]Mocking libraries for XCTest and XCUITest

When you run tests on iOS, you can mock HTTP request with several ways.
We can use such mocking for XCUITest as well.

For example, you can achieve the way using below libraries.

https://github.com/KazuCocoa/myCurrencyExchange/blob/master/myCurrencyExchangeUITests/ is the result.

If you’d like to achieve similar things based on EarlGrey, you should switch the mocking libraries with another one for unit test since EarlGrey requires unit test bundle project.

If you try to run Embassy with EarlGrey, you face non bundle resource error. It is because unit test requires App.xctest package, while XCUITest requires App.app package.

https://stackoverflow.com/questions/1879247/why-cant-code-inside-unit-tests-find-bundle-resources is probably helpful to understand the package related topic against XCTest(Unit) and XCUITest.

2 Comments

  1. Yaseen's avatar Yaseen says:

    I am using appium for automating the ios app. i want to know how to use the function defined in XCUITest library in my through appium driver or Ios driver.

    func waitForExistence(timeout: TimeInterval) -> Bool

    https://developer.apple.com/documentation/xctest/xcuielement

    1. KazuCocoa's avatar KazuCocoa says:

      Appium does not support such use case. XCUITest driver (WebDriverAgent) already calls some XCTest(UI) to find element/s and actions. You call them via Appium’s APIs.

      waitForExistence’s case, I assume you would like to wait for some conditions. In the case, you need to use wait method in your client side and call condition check method until finish the wait.
      e.g.: https://www.rubydoc.info/github/appium/ruby_lib_core/Appium%2FCore%2FWait.until_true

      You can implement waitForExistence directly in XCTest(UI). In that case, you must write your test code and relative libraries in Swift (or Objective-C).

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.