How to Get Started with XCUITest on Real Devices on Cloud
How to Get Started with XCUITest on Real Devices on Cloud
Developing for iOS applications is a popular field. Enhance your skills by learning how to run iOS tests with Apple's XCUITest platform.
Join the DZone community and get the full member experience.Join For Free
Apple’s XCUITest has quickly become very popular among iOS app developers, and testers as well. We’re extremely excited about this framework as it has enabled many of our users to adopt a new framework since UI Automation was deprecated. The XCUITest framework is not really new, as its foundation, XCTest, has been a part of the Xcode for some years already.
Let’s take a look at XCUITest and how to get started with it, and run your tests on remote real devices on a cloud service.
Mobile apps and games created for iOS devices can be tested using various different test automation frameworks. Apple has provided its own ‘official’ test automation frameworks, such as XCTest and XCUITest, as an integral part of Xcode. And as they're both tightly integrated with Xcode, both XCTest and XCUITest support writing test cases with subclasses, methods, and assertions.
Naturally, both of these frameworks are available and supported with Bitbar Testing solutions, and this blog provides all the details of how to get tests up and running on Bitbar Public Cloud using XCUITest.
Step 1: Configure Your App for Unlimited Parallelism on Real Devices
Concurrent mobile test runs are a very important factor for your efficiency and productivity, and how to use test automation to improve these. There is really only one thing you have to check to ensure your app is able to run on any of the iOS devices in the Bitbar Public Cloud. Open the Scheme Editor and verify that in the Run column all test targets are checked (enabled).
Now, check that all classes that you want to include in the test bundle are properly included with the test target membership.
NOTE! If you are using Swift, annotation @testable imports all required modules for the test bundle.
Step 2: The Right Way to Build Your IPA and Test Package
The next step is to build your application IPA and test package the right way. In order to do this properly, you should follow up all these steps to ensure the app is able to be installed, launched, and executed in any of the iOS devices in the Bitbar Public Cloud.
If you are not familiar with these frameworks, check out the XCUITest Tutorial for iOS App Testing.
Now, regardless of which framework you are using (XCTest, XCUITest, or something else), the application under test needs to be built and imported to the Bitbar Testing cloud. The following steps show you how to create an IPA that is executable on iOS devices.
In Xcode: Click Product -> Build for -> Testing.
Finally, when you are building your IPA and test package for the Bitbar Public Cloud test run, you should always build your app using a real device as a build target, as shown below:
The built application must also be packaged to ZIP file. The easiest way to do this is to use Xcode’s preview and right click Show it in Finder above the right .app file.
In Finder, right click the .app file and copy its path. This path does not change from build to build, so this step only needs to be done once.
The IPA package needed for XCTest in the Bitbar Public Cloud is a ZIP package and its creation can be automated and made part of a CI integration. Open a terminal and create the IPA as follows:
$ mkdir /tmp/Payload $ cd /tmp/Payload $ cp -r /Users/username/Desktop/Build/Products/Debug-iphoneos/LocalizationDemo.app . # app path can be pasted $ cd .. $ zip --symlinks -qr "LocalizationDemo.ipa" Payload $ ls -lrt LocalizationDemo.ipa -rw-r--r-- 1 username staff 0 Dec 16 12:42 LocalizationDemo.ipa
NOTE! If you build for iPhone 5 or iPhone 5C devices (with ARMv7 32-bit processor) then an additional step is needed before creating the build. Starting from Xcode7 onwards, ARMv7s is no longer part of the default $(ARCHS_STANDARD), and so should be added as a target build architecture.
Step 3: Login to the Bitbar Cloud and Create XCUITest Project
After you have followed all above steps, just log in to the Bitbar Public Cloud and create XCUITest project from Projects menu.
Step 4: Upload your Application IPA and Test Package
Start by clicking the green plus button on the top right corner of the view. This will open a test run creation wizard that helps in correctly setting up all of the parameters for your test. The test run creation wizard asks for both the application file (IPA) and the test package (.zip).
This is very handy, because you don’t need to change the app or test package, and you don’t have to upload it again; but the old one previously uploaded can be used for a test run.
Step 5: Select Any Number of iOS Devices for Your Test Run
This is where the real benefit of Bitbar Cloud execution comes into play. You can use any number of iOS devices for simultaneous test runs (we’re NOT limiting the number of concurrently used iOS devices anyhow!). So, pick the devices you want for a test run on the test run creation wizard step number 3.
After this is done, simply click through the wizard and start a test run. The green START button is available in all phases of the test run creation wizard on the bottom right.
All Done! Now, Let’s Take a Look at the Results!
The first thing to do after test runs are ready is to check how it did on devices you picked for a test run. The first view provides details of test success/failure on each and every device. This view also provides information on how long the test runs took.
Bitbar solutions provide all the details about the test runs and this includes recorded video of the session, screenshots, logs, performance statistics, and all fine-grained details about device session. All this material will help you to fix and shape the app to work better on real devices, the very same devices that your end-users use.
Bonus Materials for XCTest and XCUITest
More details and instructions on how to use XCTest and XCUITest for your test purposes and how to exercise those with the best practices can be found on Slideshare.
Published at DZone with permission of Ville-Veikko Helppi , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.