According to the documentation, "StoreKit testing in Xcode is a local test environment where you test in-app purchases without needing to connect to App Store servers."
Previously, it was only possible to test purchases and subscriptions in the Sandbox Environment, and that comes with a few limitations:
- It is impossible to make a purchase on a simulator (it is only possible to request a list of available purchases).
- To test purchases, you first need to set up products on App Store Connect and then use the user's sandbox environment and a real device. In this case, purchases for the developer are free. (They also are free in builds distributed through TestFlight.)
- Sandbox purchases are not visible in the Subscriptions section of the device settings, unlike purchases made in applications in production.
With the release of the new version of iOS, you can now test purchases locally. All the necessary tools are built into Xcode:
StoreKit Configuration Files let you configure products right in Xcode.
To start testing purchases, you first need to add one to your project: All the metadata for test purchases will be stored here.
It’s possible to add three types of purchases.
- Consumable In-App Purchase (can be purchased multiple times, for example, extra lives in a game.)
- Non-Consumable In-App Purchase (can be purchased only once, for example, when unlocking the full version of the app.)
- Auto-Renewable Subscription (The user gets charged a recurring fee for services or content.)
Then specify using this file instead of App Store. In the Target Run settings, select the previously created Configuration file:
StoreKit Transaction Manager stores all the test transactions and allows you to modify them. You can access it in the Debug Area.
Clicking on the button opens the manager, which shows all the completed transactions, each of which can be deleted or refunded.
StoreKit Test Framework allows you to write tests for purchases.
It has an option to disable pop-up dialogs, thereby speeding up the testing process. For the SKTestSession object, you can set the disableDialogs property to be true. Then, purchase tests can be run just like regular tests.
The Sandbox Account section in the App Store Settings on iPhone now shows test subscriptions, just like with real purchases. Additionally, you can now ignore Introductory Offers. To remind you, auto-renewable subscriptions have an option of an introductory trial period, during which the user can use premium features for free or get a discount on the subscription fee. More info on Introductory Offers is available here.
In addition, you can use the same sandbox account for testing free trials and Introductory Offers. Read more about setting up Introductory Offers here.
In the sandbox, you can also test App Store server notifications.
Here’s an example lifecycle of a subscription:
Two events — DIDRENEW and DIDCHANGERENEWALSTATUS — are coming soon. These events will be sent from the App Store to your server, notifying it of changes in the status of your in-app purchases. Read more about App Store Server Notifications here.
Another feature that will be available in the near future is testing Interrupted Purchases. To do that, you will need to go to App Store Connect to enable the Interrupt Purchases For This Tester property for the sandbox test account.
To sum it up, you can now: View and manage subscriptions on your device. Test upgrades, downgrades, cancellations, ignore introductory offers. Create sandbox tester accounts on App Store Connect if you have the Developer role. It will soon be possible to test the behavior of the application after an interrupted purchase.
You can learn more about setting up StoreKit testing in the documentation of Xcode.