XCode Automated Tests On A User Centric Application .

Posted in: Blog

In a project, we got a chance to implement XCode Automated Testing on real-time devices. Our client asked for this specific requirement for one of his business application that gives alerts to its users. He wanted us to test for the following specific functionalities of his application:

  • In-area addresses
  • Out of area addresses
  • Notification Alerts enable/disable

An automated testing service platform was used to run Tests Scripts. This platform usually provide services to test automated scripts on 100s of real-time devices.

Possible Solutions:

Implementing XCode tests was a little tricky. The major problem faced was to enable classes for automated tests. Using swift code classes in tests was creating a lot of issues. To resolve this, there were two possible solutions:

1. Make all classes and their methods public to get access in XCtests
2. Import swift code as a module in XCtests classes

It is always a bad approach to expose your private methods and members by making them public. Another major drawback with this implementation was that there were many methods involved in each class, so it was very difficult to make each method public for this purpose only. We didn’t use this approach. Importing code module in test classes was a way better approach. Importing project code as a module worked out to some extent but still there were issues related to the access of swift code classes in tests scripts. To fix this issue, we added the source files to XCTests targets as well as for all the classes required to use in tests. For instance, in a project named as “ABC App”, if a class named as “MBPopupAlertsVC.swift” was used in tests, first this would be added in “ABCTests” and then it can be used by importing ABC module in corresponding test class.

Implementation Steps:

Implementing tests by importing module will be done in the following ways:

1. Import the code module in corresponding test class.

Import ABC App
 class AlertTests: XCTestCase

2. Enable classes that you want to use in testing.

3. Write test methods starting with name “test” like the following:

func testDisableAlerts () {
XCTAssertFalse(self.isTestAlertEnabled("xctest"), "Alerts are disabled")

4. To test XCTests on real-time devices, automated testing service platform was used as mentioned earlier. To test on this platform, following things were required before tests execution:

  • Your account for using this automated testing service (free or pro)
  • iOS project .ipa file
  • iOS project .xctest file in a compressed format

To get .ipa and .xctest file, navigate to your “Product” folder in your XCode project. Select both files and right click. Select “Show in Finder” from the dropdown.

5. Upload both files to automated testing service platform.

6. Once uploaded, click on “TEST MY APP” button.

Now wait for the test executions on real-time devices. Once tests are completed, you can view the test results. Results will conclude whether tests were successful or failed.

Leave a Reply

Your email address will not be published. Required fields are marked *