> For the complete documentation index, see [llms.txt](https://jacky-chen.gitbook.io/jackychen/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jacky-chen.gitbook.io/jackychen/test/design-patterns-in-xcuitest.md).

# Design Patterns in XCUITest

[**Design Patterns in XCUITest**](https://docs.google.com/presentation/d/1Bkt3f23pXboI3UJXdEQxLtJU1YZU74QBleKXQueuEYo/mobilepresent?slide=id.p)

* Page Object&#x20;

![](https://1934061725-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4XrCDvjc3xNfiB-3eT%2F-M4Y-TstkTXMD9Y8W9l7%2F-M4Y03bS_VpL4PFxf7wP%2Fpage_object.png?alt=media\&token=13e0ab9d-0639-4eeb-b1d5-f0f66e33402e)

* Fluent Interface

![](https://1934061725-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4XrCDvjc3xNfiB-3eT%2F-M4Y-TstkTXMD9Y8W9l7%2F-M4Y03bEAjVzXLYfmN_w%2Ffluent_interface1.png?alt=media\&token=17d4e8c9-b5be-42e4-b7b1-2a7912fe4537)

* Wait until page/element load &#x20;

![](https://1934061725-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4XrCDvjc3xNfiB-3eT%2F-M4Y-TstkTXMD9Y8W9l7%2F-M4Y03bhFD6ngdMDWxZQ%2FXCTWaiter.png?alt=media\&token=a8446837-844e-4a13-a6b8-a9b3afed5048)

![](https://1934061725-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4XrCDvjc3xNfiB-3eT%2F-M4Y-TstkTXMD9Y8W9l7%2F-M4Y03biHjf6OY0dkg9c%2FXCTWaiter1.png?alt=media\&token=e38f17d3-43eb-4e0d-8797-53f7c275a1d5)

* Using check() instead of grab & hope&#x20;

![](https://1934061725-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4XrCDvjc3xNfiB-3eT%2F-M4Y-TstkTXMD9Y8W9l7%2F-M4Y03bdCPDUav5KniY4%2Fusing_check.png?alt=media\&token=2db4e37c-f8da-49d4-92cf-24eef1a62256)

* Use Launch Argument to Set Up &#x20;

![](https://1934061725-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4XrCDvjc3xNfiB-3eT%2F-M4Y-TstkTXMD9Y8W9l7%2F-M4Y03bPPKCHLV-ZeMDI%2Flaunch_argument1.png?alt=media\&token=a4633cfe-6e72-4596-9744-8b5be2c26e98)

![](https://1934061725-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4XrCDvjc3xNfiB-3eT%2F-M4Y-TstkTXMD9Y8W9l7%2F-M4Y03bQdIOcoiMMd913%2Flaunch_argument2.png?alt=media\&token=04932816-c985-4fda-ba24-5326d9b355e4)

* [**Launch Arguments**](https://www.matrixprojects.net/p/ui-testing-with-user-defaults/)

### Launch Arguments

```swift
MyAppUITest.swift
...
override func setUp() {
  super.setUp()

  let app = XCUIApplication()
  app.launchArguments.append("ui-testing")
  app.launch()
}
...

MyAppDelegate.swift
...
func setupModel() -> Model {
  let uiTesting = NSProcessInfo.processInfo().arguments.contains("ui-testing")

  let model = uiTesting ? StubModel() : NetworkModel()

  return model
}
...
```

### NSUserDefaults

```swift
MyAppUITest.swift
...
override func setUp() {
  super.setUp()

  let app = XCUIApplication()
  app.launchArguments.appendContentsOf(["-ui-testing","YES"])
  app.launch()
}
...

MyAppDelegate.swift
...
func setupModel() -> Model {
  let defaults = NSUserDefaults.standardUserDefaults()
  let uiTesting = defaults.boolForKey("ui-testing")

  let model = uiTesting ? StubModel() : NetworkModel()

  return model
}
...
```
