Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Getting Started with XCTest and XCUITest for iOS App Testing

Watch a live presentation at http://offer.bitbar.com/getting-started-with-xctest-and-xcuitest-for-ios-app-testing

XCTest has been part of Xcode for few years already, but it is finally catching up and more developers are getting on the bandwagon. XCTest and XCUITest provide feature-rich capabilities for iOS developers and test automation folks to implement different levels of tests using Xcode features and supported programming languages, Objective-C and Swift.

Stay tuned and join our upcoming webinars at http://bitbar.com/testing/webinars/

Getting Started with XCTest and XCUITest for iOS App Testing

  1. 1. TheMobile DevOps Company Ville-VeikkoHelppi HeadofDemandGeneration ville-veikko.helppi@bitbar.com GettingStarted with XCTest andXCUITest for iOS App Testing WEBINAR
  2. 2. XCTest&XCUITest • The State of The Art in iOS App Testing – Frameworks, Tools & Methods • The Basics of XCTest & XCUITest – And How to Get Started • Alternative iOS Test Automation Frameworks – Pros and Cons of Each • Demonstration • Q&A Agenda http://bitbar.com/testing/ More informationabout test automation frameworks for iOS: bitbar.com/testing/
  3. 3. PublicCloud • Device ‘Cloud’ built for internal testing use • Enterprise-grade testing infrastructure hosted by the customer • Usually sits behind customer firewall and connects to preproduction environments • Private Device Cloud • Reserved and Dedicated devices • Hosted and Fully Managed by Bitbar • Devices chosen by and reserved exclusively for customer • Also known as Testdroid Cloud • On-demand devices (multi-tenant) • Mobile App testing on over 1000+ real Android and iOS devices hosted by Bitbar Private Cloud PRODUCT UPDATE: XCTest & XCUITest Support Available On-Premise XCTest/XCUITest Supported
  4. 4. • Integral framework in Xcode • Not a new framework: Xcode 5 introduced the first version of XCTest • Incrementally new capabilities/features: o Xcode 6 – performance measurement o Xcode 7 – UI testing (XCUITest) • Works with both Swift and Objective-C XCTest & XCUITest What isXCTest/XCUITest?
  5. 5. • Easy to learn, no additional installations or components required (to Xcode) • Native iOS language support • Xcode Test Recorder (for XCUITest) • Integration with Xcode Server (continuous integration) and Bots • Faster than many other popular functional (and cross-platform) test frameworks • Works with both Swift and Objective-C XCTest Pros of XCTest
  6. 6. • No cross-platform support • Limited programming language support • Selectors may seem complex • Requires (always) a separate test target • Signing can be ‘tricky’ • Sometimes… well, flaky XCTest Cons of XCTest
  7. 7. The Status of iOS Test Automation Frameworks
  8. 8. • If you running a test script built for prior Xcode versions, all uia_* calls will raise an error with the latest Xcode • When upgrading to Xcode 8 all your existing UIAutomation scripts will fail Deprecated UI Automation MigratingUIA-> XCTest?
  9. 9. The Basics of XCTest & XCUITest and How to Get Started New Ebook Available! Download This Guide
  10. 10. • 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 class XCTest & XCUITest Getting Started -(void)testExample { XCTAssert(...); XCTAssertTrue(...); XCTAssertFalse(...); }
  11. 11. • Tests are grouped into classes that are subclass from XCTestCase XCTest & XCUITest WritingTest Methods class 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. }]; } }
  12. 12. XCTest & XCUITest XCTestCase Example - Swift import UIKit import 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") } }
  13. 13. • 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 runs XCTest & XCUITest WritingPerformance 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<100000; i++) { [calcViewController press:[calcView viewWithTag:13]]; [calcViewController press:[calcView viewWithTag: 2]]; [calcViewController press:[calcView viewWithTag:12]]; } }]; }
  14. 14. XCUIApplication • The XCUIApplication is basically a proxy for an app that can be launched and terminated • User can tell the application to run in testing mode by defining app as a “Target Application” in Xcode target settings Code Syntax (XCUITest) // Objective-C XCUIApplication *app = [[XCUIApplication alloc] init]; // Swift let app = XCUIApplication()
  15. 15. XCUIElement • XCUIElement is the actual UI element in an iOS application • XCUIElement provides all the basics symbols and functions for UI element interactions • Gestures with XCTest include clicking UI elements (normal, double, pressing), interacting with the screen (swipe, pinch, zoom, rotate etc.) Code Syntax (XCUITest) // Click-based functions tap() doubleTap() twoFingerTap() tap(withNumberOfTaps: UInt, numberOfTouches: UInt) press(forDuration: TimeInterval) press(forDuration: TimeInterval, thenDragTo: XCUIElement) // Generic UI interactions swipeLeft() swipeRight() swipeUp() swipeDown() pinch(withScale: CGFloat, velocity: CGFloat) rotate(CGFloat, withVelocity: CGFloat)
  16. 16. XCUIElement • XCUIElement is constructed using the actual user interface elements on the screen • XCUIElement inherits from NSObject • In order to perform any interaction (tap on this example) on a UI element the UI interactions are available for use. Code Syntax (XCUITest) XCUIApplication *app = [[XCUIApplication alloc] init]; XCUIElement *masterNavigationBar = app.navigationBars[@"Master"]; XCUIElement *editButton = masterNavigationBar.buttons[@"Edit"]; // Objective-C [masterNavigationBar.staticTexts[@"Master"] tap]; [editButton tap];
  17. 17. • Two ways to create IPA for test automation 1. Working with Xcode 2. Working from Command Line • Test package can be built as APP file and zipped for cloud execution Preparing IPA and Test Package for Simultaneous Device Runs Methods to Create IPAand Test Package for Simultaneous Tests
  18. 18. • By archiving any build package will be compatible with an iOS device • When your build is done and archiving has finished, select the build from Archive list and click “Export…” Working on Xcode to Create IPA for Testing 1. Archive Your Build
  19. 19. • When the following window is shown, simply select “Save for Ad Hoc Deployment” and click Next. Working on Xcode to Create IPA for Testing 2. Select The Right Method
  20. 20. • Use the same identify what you use in build settings for code signing. • If your project and Xcode is properly configured you should see the following type of dialog proposing the first usable identifier: Working on Xcode to Create IPA for Testing 3. Identify Yourself(andYourBuild)
  21. 21. • It’s almost always recommended to include all possible device support for your app. • If you want to reduce the size of your IPA you can shrink it by selecting to support only certain devices and OS versions Working on Xcode to Create IPA for Testing 4. Select OS and Devices
  22. 22. • This can be done Product -> Build for -> Testing menu: Working on Command Line to Create IPA for Testing 1. Select toBuildfor Testing
  23. 23. • 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 Fileon HD
  24. 24. • 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 FileProperly
  25. 25. • 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/LocalizationDemo.app . $ cd .. $ zip --symlinks -qr "LocalizationDemo.ipa" Payload $ ls -lrt LocalizationDemo.ipa -rw-r--r-- 1 username staff 0 Dec 16 12:42 LocalizationDemo.ipa
  26. 26. • 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!
  27. 27. Quick XCTest/XCUITest Comparison Ebooks Available for… XCTest/ XCUITest Calabash Appium
  28. 28. Top 3 iOS Test Automation Frameworks XCTEST/XCUITEST APPIUM CALABASH CROSS-PLATFORM No Yes Yes IOS Yes Yes Yes MOBILE WEB Yes Yes No LANGUAGE Obj-C/Swift Almost any Ruby TOOL FOR TEST CREATION Xcode Appium.app CLI (Human-Readable syntax) COMMUNITY Apple Community Community
  29. 29. Demo Xcode 6 / 7 / 8
  30. 30. Summary– Q&A Moreinformationaboutmobileapptesting, mobilemonitoringandmobiledevopsat bitbar.com

    Be the first to comment

    Login to see the comments

  • vhelppi

    Jan. 25, 2017
  • suhebsjamadar

    Aug. 20, 2017
  • MalteBehrendt

    Sep. 19, 2018
  • KelseyMaddy

    Nov. 14, 2018

Watch a live presentation at http://offer.bitbar.com/getting-started-with-xctest-and-xcuitest-for-ios-app-testing XCTest has been part of Xcode for few years already, but it is finally catching up and more developers are getting on the bandwagon. XCTest and XCUITest provide feature-rich capabilities for iOS developers and test automation folks to implement different levels of tests using Xcode features and supported programming languages, Objective-C and Swift. Stay tuned and join our upcoming webinars at http://bitbar.com/testing/webinars/

Views

Total views

10,775

On Slideshare

0

From embeds

0

Number of embeds

5,824

Actions

Downloads

48

Shares

0

Comments

0

Likes

4

×