Fashionable XCUITest for iOS Apps
SauceCon 2019
Shashikant Jagtap
@Shashikant86
About Me
• Shashikant Jagtap [ XCTEQ Limited ]
• Background: Mobile DevOps, CI/CD & Test Automation
• XCUITest, XCTest, Swift, Developer Tools, CI Scripting
• XCBLOG [https://shashikantjagtap.net]
@Shashikant86
Topics
• State of iOS App Testing
• XCUITest
• Protocol Oriented Test Design Pattern
• Tips and Tricks for DevOps friendly XCUITests
@Shashikant86
iOS Testing without XCUITest
• Heavy Manual Testing
• Use of third-party tools
• Slow and Flaky Test Automation
• Hard to integrate with CI/CD pipeline
@Shashikant86
XCUITest
• Xcode UI Testing framework from
• Allows UI Testing using Swift or Objective-C programming languages
• Based on Accessibility technology
• Black Box
@Shashikant86
How to learn XCUITest
• Apple WWDC Videos
https://developer.apple.com/videos/play/wwdc2015/406/
• Apple Official Documentation on UI Testing
https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/09-ui_testing.html
• Test Automation University Course on XCUITest
https://testautomationu.applitools.com/introduction-to-ios-test-automation-with-xcuitest/
@Shashikant86
XCUITest Test Design Pattern
• Page Object Pattern or Screen Play Pattern
@Shashikant86
XCUITest Test Design Pattern
• Page Object Pattern or Screen Play Pattern
• Why?
@Shashikant86
XCUITest Test Design Pattern
• Page Object Pattern or Screen Play Pattern
• Why?
• Swift is protocol oriented language
https://developer.apple.com/videos/play/wwdc2015/408/
@Shashikant86
XCUITest Test Design Pattern
• Page Object Pattern or Screen Play Pattern
• Why?
• Swift is protocol oriented language
https://developer.apple.com/videos/play/wwdc2015/408/
• We can use Protocol Oriented Approach for test designing too!
@Shashikant86
Protocol Oriented XCUITest
@Shashikant86
https://testautomationu.applitools.com/introduction-to-ios-test-automation-with-xcuitest/
Protocol Oriented XCUITest
• Scalable Steps across UI Test Target
• One Suite for both iPad and Phone
• Human Readable and Re-usable Steps with XCTActivity
• Easy to Configure on CI
@Shashikant86
Effective XCTest for iOS
• Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance
Testing
@Shashikant86
Effective XCTest for iOS
• Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance
Testing
• Make Accessibility Identifiers mandatory all UI elements
@Shashikant86
Effective XCTest for iOS
• Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance
Testing
• Make Accessibility Identifiers mandatory all UI elements
• Separate Configuration for testing. Don’t use debug or release.
@Shashikant86
Effective XCTest for iOS
• Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance
Testing
• Make Accessibility Identifiers mandatory all UI elements
• Separate Configuration for testing. Don’t use debug or release
• Think if testing on real devices required?
@Shashikant86
Effective XCTest for iOS
• Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance
Testing
• Make Accessibility Identifiers mandatory all UI elements
• Separate Configuration for testing. Don’t use debug or release
• Think if testing on real devices required?
• Write loads of API and Contract Tests, Reduce the burden on UI testing
@Shashikant86
Effective XCTest for iOS
• Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance
Testing
• Make Accessibility Identifiers mandatory all UI elements
• Separate Configuration for testing. Don’t use debug or release
• Think if testing on real devices required?
• Write loads of API and Contract Tests, Reduce the burden on UI testing
• Write performance tests for detecting run time issues
@Shashikant86
Effective XCTest for iOS
• Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance Testing
• Make Accessibility Identifiers mandatory all UI elements
• Separate Configuration for testing. Don’t use debug or release
• Think if testing on real devices required?
• Write loads of API and Contract Tests, Reduce the burden on UI testing
• Write performance tests for detecting run time issues
• Keep separate Xcode schemes for UI and Performance tests
@Shashikant86
Stub/Mock for XCUITest
• Stubbing or mocking is hard with Swift. Harder for XCUITest
@Shashikant86
Stub/Mock for XCUITest
• Stubbing or mocking is hard with Swift. Harder for XCUITest
• Launch Arguments Or Launch Environments in application code
@Shashikant86
Stub/Mock for XCUITest
• Stubbing or mocking is hard with Swift. Harder for XCUITest
• Launch Arguments Or Launch Environments in application code
• Local Networking Stubbing ( Swifter, Embassy, SBTUITestTunnel, Server
Side Swift framework, SwiftLocalhost etc)
@Shashikant86
Stub/Mock for XCUITest
• Stubbing or mocking is hard with Swift. Harder for XCUITest
• Launch Arguments Or Launch Environments in application code
• Local Networking Stubbing ( Swifter, Embassy, SBTUITestTunnel, Server
Side Swift framework, SwiftLocalhost etc)
• Stub if really needed. Keep UI tests as real tests.
@Shashikant86
CI Friendly XCUITest
• Select smart CI Server/Services
@Shashikant86
CI Friendly XCUITest
• Select smart CI Server/Services
• Avoid third party tools/Services if possible for shorter build time
@Shashikant86
CI Friendly XCUITest
• Select smart CI Server/Services
• Avoid third party tools/Services if possible for shorter build time
• Don’t build app twice. Use build-for-testing and test-without-building
option from xcodebuild tool
@Shashikant86
CI Friendly XCUITest
• Select smart CI Server/Services
• Avoid third party tools/Services if possible for shorter build time
• Don’t build app twice. Use build-for-testing and test-without-building
option from xcodebuild tool
• Avoid Flaky CI scripting, Keep it native.
@Shashikant86
CI Friendly XCUITest
• Select smart CI Server/Services
• Avoid third party tools/Services if possible for shorter build time
• Don’t build app twice. Use build-for-testing and test-without-building
option from xcodebuild tool
• Avoid Flaky CI scripting, Keep it native.
• Smart parallelisation of XCTest to speed up builds
@Shashikant86
Dealing with Flakiness
• You can’t simply avoid flakiness in UI tests ( trade-off )
@Shashikant86
Dealing with Flakiness
• You can’t simply avoid flakiness in UI tests ( trade-off )
• UI Tests != Unit Tests
@Shashikant86
Dealing with Flakiness
• You can’t simply avoid flakiness in UI tests ( trade-off )
• UI Tests != Unit Tests
• Root of flakiness aren not your test. It can be anything out of your control.
e.g Environment, Flaky app architecture, Test data, Network etc
@Shashikant86
Dealing with Flakiness
• You can’t simply avoid flakiness in UI tests ( trade-off )
• UI Tests != Unit Tests
• Root of flakiness aren not your test. It can be anything out of your control.
e.g Environment, Flaky app architecture, Test data, Network etc
@Shashikant86
Dealing with Flakiness
• “Your test code requires maintenance. There is no getting around this.”
Angie Jones
[ https://dzone.com/articles/testing-in-ci ]
@Shashikant86
Benefits of XCUITest
• Native and Fast
• Collaboration with app developers
• Easy to integrate with CI/CD
• Enhance the accessibility of the iOS apps
• Maintained by Apple
@Shashikant86
Excuses for not using XCUITest
• XCUITest is great but we made decision in the past to use other third-
party tool. We invested heavily in it.
@Shashikant86
Excuses for not using XCUITest
• XCUITest is great but we made decision in the past to use other third-
party tool. We invested heavily in it.
• We want cross-platform solution for both iOS and Android
@Shashikant86
Excuses for not using XCUITest
• XCUITest is great but we made decision in the past to use other third-
party tool. We invested heavily in it.
• We want cross-platform solution for both iOS and Android
• Where should we find engineers with Swift and XCUITest skills?
@Shashikant86
Excuses for not using XCUITest
• XCUITest is great but we made decision in the past to use other third-
party tool. We invested heavily in it.
• We want cross-platform solution for both iOS and Android
• Where should we find engineers with Swift and XCUITest skills?
• It’s still a new and buggy!
@Shashikant86
Excuses for not using XCUITest
• XCUITest is great but we made decision in the past to use other third-
party tool. We invested heavily in it.
• We want cross-platform solution for both iOS and Android
• Where should we find engineers with Swift and XCUITest skills?
• It’s still a new and buggy!
• We keep using existing tool as long as it works.
@Shashikant86
Recap
• XCUITest should be used for native iOS Apps
• Cross-platform mobile development, you can choose cross-platform
testing tools
• XCUITest gives chance to collaborate with developers and finds internal
issues in the app.
@Shashikant86
Question Time
@Shashikant86
Thanks
• Contact Me: @Shashikant86
• Email: shashikant.jagtap@xcteq.co.uk
• Website: [ https://shashikantjagtap.net ]
@Shashikant86

Fashionable XCUITest for iOS Apps by Shashikant Jagtap

  • 1.
    Fashionable XCUITest foriOS Apps SauceCon 2019 Shashikant Jagtap @Shashikant86
  • 2.
    About Me • ShashikantJagtap [ XCTEQ Limited ] • Background: Mobile DevOps, CI/CD & Test Automation • XCUITest, XCTest, Swift, Developer Tools, CI Scripting • XCBLOG [https://shashikantjagtap.net] @Shashikant86
  • 3.
    Topics • State ofiOS App Testing • XCUITest • Protocol Oriented Test Design Pattern • Tips and Tricks for DevOps friendly XCUITests @Shashikant86
  • 4.
    iOS Testing withoutXCUITest • Heavy Manual Testing • Use of third-party tools • Slow and Flaky Test Automation • Hard to integrate with CI/CD pipeline @Shashikant86
  • 5.
    XCUITest • Xcode UITesting framework from • Allows UI Testing using Swift or Objective-C programming languages • Based on Accessibility technology • Black Box @Shashikant86
  • 6.
    How to learnXCUITest • Apple WWDC Videos https://developer.apple.com/videos/play/wwdc2015/406/ • Apple Official Documentation on UI Testing https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/09-ui_testing.html • Test Automation University Course on XCUITest https://testautomationu.applitools.com/introduction-to-ios-test-automation-with-xcuitest/ @Shashikant86
  • 7.
    XCUITest Test DesignPattern • Page Object Pattern or Screen Play Pattern @Shashikant86
  • 8.
    XCUITest Test DesignPattern • Page Object Pattern or Screen Play Pattern • Why? @Shashikant86
  • 9.
    XCUITest Test DesignPattern • Page Object Pattern or Screen Play Pattern • Why? • Swift is protocol oriented language https://developer.apple.com/videos/play/wwdc2015/408/ @Shashikant86
  • 10.
    XCUITest Test DesignPattern • Page Object Pattern or Screen Play Pattern • Why? • Swift is protocol oriented language https://developer.apple.com/videos/play/wwdc2015/408/ • We can use Protocol Oriented Approach for test designing too! @Shashikant86
  • 11.
  • 12.
    Protocol Oriented XCUITest •Scalable Steps across UI Test Target • One Suite for both iPad and Phone • Human Readable and Re-usable Steps with XCTActivity • Easy to Configure on CI @Shashikant86
  • 13.
    Effective XCTest foriOS • Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance Testing @Shashikant86
  • 14.
    Effective XCTest foriOS • Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance Testing • Make Accessibility Identifiers mandatory all UI elements @Shashikant86
  • 15.
    Effective XCTest foriOS • Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance Testing • Make Accessibility Identifiers mandatory all UI elements • Separate Configuration for testing. Don’t use debug or release. @Shashikant86
  • 16.
    Effective XCTest foriOS • Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance Testing • Make Accessibility Identifiers mandatory all UI elements • Separate Configuration for testing. Don’t use debug or release • Think if testing on real devices required? @Shashikant86
  • 17.
    Effective XCTest foriOS • Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance Testing • Make Accessibility Identifiers mandatory all UI elements • Separate Configuration for testing. Don’t use debug or release • Think if testing on real devices required? • Write loads of API and Contract Tests, Reduce the burden on UI testing @Shashikant86
  • 18.
    Effective XCTest foriOS • Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance Testing • Make Accessibility Identifiers mandatory all UI elements • Separate Configuration for testing. Don’t use debug or release • Think if testing on real devices required? • Write loads of API and Contract Tests, Reduce the burden on UI testing • Write performance tests for detecting run time issues @Shashikant86
  • 19.
    Effective XCTest foriOS • Use XCTest for all kinds of tests. Unit, Integration, API, UI and Performance Testing • Make Accessibility Identifiers mandatory all UI elements • Separate Configuration for testing. Don’t use debug or release • Think if testing on real devices required? • Write loads of API and Contract Tests, Reduce the burden on UI testing • Write performance tests for detecting run time issues • Keep separate Xcode schemes for UI and Performance tests @Shashikant86
  • 20.
    Stub/Mock for XCUITest •Stubbing or mocking is hard with Swift. Harder for XCUITest @Shashikant86
  • 21.
    Stub/Mock for XCUITest •Stubbing or mocking is hard with Swift. Harder for XCUITest • Launch Arguments Or Launch Environments in application code @Shashikant86
  • 22.
    Stub/Mock for XCUITest •Stubbing or mocking is hard with Swift. Harder for XCUITest • Launch Arguments Or Launch Environments in application code • Local Networking Stubbing ( Swifter, Embassy, SBTUITestTunnel, Server Side Swift framework, SwiftLocalhost etc) @Shashikant86
  • 23.
    Stub/Mock for XCUITest •Stubbing or mocking is hard with Swift. Harder for XCUITest • Launch Arguments Or Launch Environments in application code • Local Networking Stubbing ( Swifter, Embassy, SBTUITestTunnel, Server Side Swift framework, SwiftLocalhost etc) • Stub if really needed. Keep UI tests as real tests. @Shashikant86
  • 24.
    CI Friendly XCUITest •Select smart CI Server/Services @Shashikant86
  • 25.
    CI Friendly XCUITest •Select smart CI Server/Services • Avoid third party tools/Services if possible for shorter build time @Shashikant86
  • 26.
    CI Friendly XCUITest •Select smart CI Server/Services • Avoid third party tools/Services if possible for shorter build time • Don’t build app twice. Use build-for-testing and test-without-building option from xcodebuild tool @Shashikant86
  • 27.
    CI Friendly XCUITest •Select smart CI Server/Services • Avoid third party tools/Services if possible for shorter build time • Don’t build app twice. Use build-for-testing and test-without-building option from xcodebuild tool • Avoid Flaky CI scripting, Keep it native. @Shashikant86
  • 28.
    CI Friendly XCUITest •Select smart CI Server/Services • Avoid third party tools/Services if possible for shorter build time • Don’t build app twice. Use build-for-testing and test-without-building option from xcodebuild tool • Avoid Flaky CI scripting, Keep it native. • Smart parallelisation of XCTest to speed up builds @Shashikant86
  • 29.
    Dealing with Flakiness •You can’t simply avoid flakiness in UI tests ( trade-off ) @Shashikant86
  • 30.
    Dealing with Flakiness •You can’t simply avoid flakiness in UI tests ( trade-off ) • UI Tests != Unit Tests @Shashikant86
  • 31.
    Dealing with Flakiness •You can’t simply avoid flakiness in UI tests ( trade-off ) • UI Tests != Unit Tests • Root of flakiness aren not your test. It can be anything out of your control. e.g Environment, Flaky app architecture, Test data, Network etc @Shashikant86
  • 32.
    Dealing with Flakiness •You can’t simply avoid flakiness in UI tests ( trade-off ) • UI Tests != Unit Tests • Root of flakiness aren not your test. It can be anything out of your control. e.g Environment, Flaky app architecture, Test data, Network etc @Shashikant86
  • 33.
    Dealing with Flakiness •“Your test code requires maintenance. There is no getting around this.” Angie Jones [ https://dzone.com/articles/testing-in-ci ] @Shashikant86
  • 34.
    Benefits of XCUITest •Native and Fast • Collaboration with app developers • Easy to integrate with CI/CD • Enhance the accessibility of the iOS apps • Maintained by Apple @Shashikant86
  • 35.
    Excuses for notusing XCUITest • XCUITest is great but we made decision in the past to use other third- party tool. We invested heavily in it. @Shashikant86
  • 36.
    Excuses for notusing XCUITest • XCUITest is great but we made decision in the past to use other third- party tool. We invested heavily in it. • We want cross-platform solution for both iOS and Android @Shashikant86
  • 37.
    Excuses for notusing XCUITest • XCUITest is great but we made decision in the past to use other third- party tool. We invested heavily in it. • We want cross-platform solution for both iOS and Android • Where should we find engineers with Swift and XCUITest skills? @Shashikant86
  • 38.
    Excuses for notusing XCUITest • XCUITest is great but we made decision in the past to use other third- party tool. We invested heavily in it. • We want cross-platform solution for both iOS and Android • Where should we find engineers with Swift and XCUITest skills? • It’s still a new and buggy! @Shashikant86
  • 39.
    Excuses for notusing XCUITest • XCUITest is great but we made decision in the past to use other third- party tool. We invested heavily in it. • We want cross-platform solution for both iOS and Android • Where should we find engineers with Swift and XCUITest skills? • It’s still a new and buggy! • We keep using existing tool as long as it works. @Shashikant86
  • 40.
    Recap • XCUITest shouldbe used for native iOS Apps • Cross-platform mobile development, you can choose cross-platform testing tools • XCUITest gives chance to collaborate with developers and finds internal issues in the app. @Shashikant86
  • 41.
  • 42.
    Thanks • Contact Me:@Shashikant86 • Email: shashikant.jagtap@xcteq.co.uk • Website: [ https://shashikantjagtap.net ] @Shashikant86