Getting Started with XCTest and XCUITest for iOS App Testing

  • Published on

  • View

  • Download

Embed Size (px)


PowerPoint Presentation

The Mobile DevOps CompanyVille-Veikko HelppiHead of Demand Generationville-veikko.helppi@bitbar.comGetting Started with XCTest and XCUITest for iOS App TestingWEBINAR

XCTest & XCUITestThe State of The Art in iOS App Testing Frameworks, Tools & MethodsThe Basics of XCTest & XCUITest And How to Get StartedAlternative iOS Test Automation Frameworks Pros and Cons of EachDemonstrationQ&A

Agenda information about test automation frameworks for iOS:

Public CloudDevice Cloud built for internal testing useEnterprise-grade testing infrastructure hosted by the customerUsually sits behind customer firewall and connects to preproduction environments

Private Device CloudReserved and Dedicated devicesHosted and Fully Managed by BitbarDevices chosen by and reserved exclusively for customerAlso known as Testdroid CloudOn-demand devices (multi-tenant)Mobile App testing on over 1000+ real Android and iOS devices hosted by Bitbar


XCTest & XCUITest Support Available

On-PremiseXCTest/XCUITest Supported

Integral framework in XcodeNot a new framework: Xcode 5 introduced the first version of XCTestIncrementally new capabilities/features:Xcode 6 performance measurementXcode 7 UI testing (XCUITest)Works with both Swift and Objective-C

XCTest & XCUITest

What is XCTest/XCUITest?

Easy to learn, no additional installations or components required (to Xcode) Native iOS language supportXcode Test Recorder (for XCUITest)Integration with Xcode Server (continuous integration) and BotsFaster than many other popular functional (and cross-platform) test frameworksWorks with both Swift and Objective-C

XCTestPros of XCTest

No cross-platform supportLimited programming language supportSelectors may seem complexRequires (always) a separate test targetSigning can be trickySometimes well, flakyXCTestCons of XCTest

The Status of iOS Test Automation Frameworks

If you running a test script built for prior Xcode versions, all uia_* calls will raise an error with the latest XcodeWhen upgrading to Xcode 8 all your existing UIAutomation scripts will fail

Deprecated UI Automation

Migrating UIA -> XCTest?

The Basics of XCTest & XCUITest andHow to Get StartedNew Ebook Available!

Download This Guide

A test method is an instance method of a test class that begins with prefix test

Tests are simply classes and methods and e.g. @property and helper methods can be added to the classXCTest & XCUITest

Getting Started-(void)testExample {XCTAssert(...);XCTAssertTrue(...);XCTAssertFalse(...);}

Tests are grouped into classes that are subclass from XCTestCaseXCTest & XCUITest

Writing Test Methodsclass DemoTest: XCTestCase {

- (void)testExample { // This is an example of a functional test case. // Use XCTAssert and related functions} - (void)testPerformanceExample { // This is an example of a performance test case. [self measureBlock:^{ // Put the code you want to measure the time of here. }];}}

XCTest & XCUITest

XCTestCase Example - Swiftimport UIKitimport XCTest

@testable import LocalizationDemo

class LocalizationDemoTests: XCTestCase { override func setUp() { super.setUp() } override func tearDown() { super.tearDown() } func testMyModel() { // Example of a functional test case. var model = MyModel(name: "first", surname: "last"); XCTAssertEqual(model.a, "first"); XCTAssertNotEqual(model.b, "first"); } func testIfLocalizationWorks() { // This is an example of a functional test case. XCTAssert(true, "Pass") }}

A performance test takes a block of code (that is measured) and runs it ten times, collecting the average execution time and the standard deviation for the runsXCTest & XCUITest

Writing Performance Tests- (void) testAdditionPerformance { [self measureBlock:^{ // set the initial state [calcViewController press:[calcView viewWithTag: 6]]; // iterate for 100000 cycles of adding 2 for (int i=0; i Build for -> Testing menu:Working on Command Line to Create IPA for Testing

1. Select to Build for Testing

Next, select your project in Project Navigator and right click to Show it in Finder:Working on Command Line to Create IPA for Testing

2. Locate App File on HD

After Finder dialog has been opened and files are shown, just highlight the .app file and right-click to see copying option, as follows:Working on Command Line to Create IPA for Testing

3. Copy App File Properly

After Finder dialog has been opened and files are shown, just highlight the .app file and right-click to see copying option, as follows:Working on Command Line to Create IPA for Testing

4. Create IPA from CMD$ mkdir /tmp/Payload$ cd /tmp/Payload$ cp -r /User/Path/Debug-iphoneos/ . $ cd ..$ zip --symlinks -qr "LocalizationDemo.ipa" Payload$ ls -lrt LocalizationDemo.ipa-rw-r--r-- 1 username staff 0 Dec 16 12:42 LocalizationDemo.ipa

If building for iPhone 5 or iPhone 5C (with ARMv7 32-bit processor) devices, additional step is needed before creating the build. Starting from Xcode 7, armv7s is no more part of the default $(ARCHS_STANDARD) and so should be added as a target build architecture

Creating an IPA for iOS App Testing

Good To Know!

Quick XCTest/XCUITest ComparisonEbooks Available for


Top 3 iOS Test Automation FrameworksXCTEST/XCUITESTAPPIUMCALABASHCROSS-PLATFORMNoYesYesIOSYesYesYesMOBILE WEBYesYesNoLANGUAGEObj-C/SwiftAlmost anyRubyTOOL FOR TEST CREATIONXcodeAppium.appCLI (Human-Readable syntax)COMMUNITYAppleCommunityCommunity


Xcode 6 / 7 / 8

Summary Q&A

More information about mobile app testing, mobile monitoring and mobile devops at