Many apps have paid subscriptions for users to access premium features. Testing a subscription can be as challenging as developing it. In this article, we will go over the complete process of subscription testing.
I am going to outline to you step by step how the Apple Sandbox environment is used to test subscriptions prior to the rollout of subscription code changes. I’ll also talk about how TestFlight and production Testing can also be used to test the in-app subscription. There are definitely some takeaways that you will be interested in.
Types of Subscription Testing
Subscription testing is categorized into three categories: Sandbox testing, TestFlight (production Sandbox) testing and production testing.
Sandbox Subscription Testing
The Sandbox environment lets you test in-app subscription transactions without creating actual transactions. It uses the Apple Store infrastructure to simulate all subscription transactions. Sandbox is able to return a transaction as if it had been processed.
Create A Sandbox Account
First of all, to do any type of subscription testing, you need to create a Sandbox tester account:
- 1. Login to your iTunes Connect Account-> Users and Access -> Sandbox ->Testers to create new testers.
- 2. On your device, go to Settings-> App Store -> LogIn to your Sandbox Account.
How to Test Subscriptions
Sandbox testing is categorized into developer and production. There are no feature differences between these two. The only difference is that if you are running the app through Xcode, then Sandbox testing will use the developer Sandbox, whereas if your app is distributed through TestFlight, then Sandbox testing will use the production Sandbox.
Reduce Subscription Testing Duration
Sandbox automatically decreases the duration of auto-renewable subscriptions to allow shortened testing times. You can see below that the actual subscription of one year, for example, was reduced to one hour for testing purposes. Why wait a whole year to test the subscription?
Sandbox also auto-renews the subscription five more times and then expires.
Subscription Test Cases
Sandbox allows developers to test transactions such as multiple purchases, renewals, and expirations. In Sandbox, untested code is isolated from the production environment for testing purposes. It literally is a Sandbox to play in!
To begin testing, you must log in to your Sandbox account in iOS Settings > iTunes & App Store as shown below underlined in red.
Let’s dive into testing a subscription purchase, auto-renewal, restore and expiration.
Test Case 1: Test for Subscription Purchase, Auto-Renewal, and Expiration
You can test your app subscription to ensure it can be purchased, auto-renewed, and will expire after five subscription renewals by following these steps:
- 1. Subscribe to your app subscription.
- 2. Close the app and open it after one hour to make sure your app is still in an active subscription state. I chose one hour here because one year translates to one hour in a Sandbox environment.
- 3. Close the app and open it again after about six hours (allowing five auto-renewals), and your app should be reset to the unsubscribed state. Sandbox automatically renews subscriptions up to five times and then sets the subscription as inactive.
Test Case 2: Test Restore Purchase for an Active Subscription
Using Sandbox, your app can be tested to ensure that it has an active subscription and if deleted, then reinstalled on the device, the active subscription associated with the user will be restored.
One major drawback in Sandbox testing is that a subscription receipt isn't generated until you make a purchase, whereas in the production environment, a subscription receipt file is sent to the device as soon as the app is installed and can be validated for a subscription purchase.
Restoring an active subscription using Sandbox can be tested by:
- 1. Subscribe to auto-renewable subscription on your app.
- 2. Delete the app on your device.
- 3. Reinstall the app and press the Restore Purchase button.
-
4. If all these steps are done within the time of the subscription test duration, then an active subscription will be restored. Otherwise, the user can be notified using an error pop-up that no active subscription was found.
Test Case 3: Test Restore Purchase for an Active Subscription on Multiple Devices
Adding a single subscription purchase on multiple owned devices can be tested on Sandbox. For example, if the user had both an iPhone and iPad, they can use the same subscription on both devices.
Testing the AccuWeather app subscription for multiple devices can be tested as follows:
- 1. Launch the app on the iPad and press the Restore Purchase subscription button.
- 2. Log into Sandbox on both the iPhone and iPad using the same Sandbox account.
- 3. Subscribe to the subscription on the iPhone.
- 4. Install the AccuWeather app on your iPad.
- 5. If all these steps are done within the time of the subscription test duration, then an active subscription will be loaded on the second device. Otherwise, the user can be notified using an error pop-up that no active subscription was found.
Sandbox Reliability
Developer Sandbox is famously unreliable. For some reason, Apple never addressed it or they may not understand the inconsistency. Either way, don’t get stressed if it doesn’t work all the time.
TestFlight Subscription Testing
An application distributed by TestFlight uses the production Sandbox environment by default, therefore all testing steps will stay the same as the development Sandbox environment.
Production Subscription Testing
For an app that has not been released on the App Store, using an early version of the approved app is a great way to test subscriptions. Below are the steps for testing:
- 1. For this, you need to submit the app’s beta version to Apple’s review in iTunesConnect. Don’t forget to set the version release to manual release.
- 2. Generate promo codes for the app from iTunesConnect.
- 3. Using the promo code, download the app from the App Store.
- 4. Subscribe to your subscription. As the app is approved by Apple (but not released), it will still perform the same way as a live app.
Important Takeaways
Sandbox environment has reduced subscription duration which is helpful in testing.
There is no purchase subscription receipt available in the Sandbox environment until a purchase is made.
Testers will not be charged for the subscription purchases done in either the development or production Sandbox environment.
References:
Anurag Pandey
AccuWeather Senior iOS Developer
An iOS enthusiast with a passion to dive deeply into architectures, design patterns, standard principles and explore new technologies.