Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up UI test cases in Xcode?

Tags:

Since Xcode 7 we have a nice API for UI testing. Mostly I'm satisfied with it. The only concern is related to the speed.

In the beginning an ordinary UI test case (about 15 actions) ran approximately 25 seconds. Then I mocked networking completely. Now it takes 20 seconds. Considering the fact that the time is taken only by animations and a launch time (1 second or even less), I assume, there must be a way to speed it up.

like image 575
Artem Stepanenko Avatar asked May 17 '16 17:05

Artem Stepanenko


People also ask

How do I test UI in Xcode?

How to Run XCUI Tests on XCode. To run the XCUITests on XCode, you can click the highlighted icon below to see your newly created UI Test targets. You can hover on the “testExample()” test case and click the “Play” icon to run that specific test to see if everything was set up properly.

What is XCTest XCUITest?

Key Concepts of XCUITest XCTest: XCTest is a testing framework that allows you to create and run UI tests, unit tests, and performance tests for your Xcode projects in Swift and Objective-C languages. It is pre-built with Xcode.

How do I run all test cases in Xcode?

⌘U will build and run all your test cases. It is the most commonly used shortcut when creating unit test cases. It is equivalent to ⌘R (build & run) while doing app development. You can use this shortcut to build your test target and run all the test cases in your test target.


1 Answers

Try setting this property when your UI tests run:

UIApplication.shared.keyWindow?.layer.speed = 100 

Here's how I set it:

func application(_ application: UIApplication,                  didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {      if ProcessInfo.processInfo.arguments.contains("UITests") {         UIApplication.shared.keyWindow?.layer.speed = 100     } } 

And in my UI tests:

class MyAppUITests: XCTestCase {      // MARK: - SetUp / TearDown      override func setUp() {         super.setUp()          let app = XCUIApplication()         app.launchArguments = ["UITests"]         app.launch()     } } 

There's a few more handy tips in this blog post.

like image 198
Mark Avatar answered Sep 22 '22 13:09

Mark