Get started with StoreKit Testing in Xcode
Learn how to test in-app purchases locally.
04 Sep 2023 · 4 min read
With StoreKit Testing in Xcode, Apple introduced the possibility to simulate and test in-app purchases and subscriptions in a controlled environment. By using StoreKit Testing, we can now test in-app purchases locally in Xcode without needing to connect to App Store Connect.
In this article, we'll look at how this approach works.
Let's dive in.
To setup StoreKit testing in Xcode, the following steps are required:
- Creating and configuring a StoreKit configuration file.
- Enabling StoreKit testing in Xcode.
- Test purchasing products.
Let's look at each step in more detail.
1. Creating a StoreKit configuration file
A StoreKit configuration file contains the in-app purchase options and their configurations. To create a StoreKit configuration file, Xcode provides a template:
There are two types of StoreKit configuration files:
- local - which we can use if we didn't set up the iOS application in App Store Connect or in case we want to try out new types of in-app purchases or subscriptions before setting them up in App Store Connect
- synced - which we can use if we already did setup in-app purchases in App Store Connect and would like to test them in Xcode.
Let's look at how to use both types of configuration files.
1.1 Configuring a local StoreKit configuration file
After creating a StoreKit configuration file, we can start configuring in-app purchase options the iOS application will provide.
As shown above, we can use the + button to configure different types of in-app purchases, set their product ids etc.
1.2 Configuring a synced StoreKit configuration file
To use a synced file, the creation dialog provides a sync option where we can configure which team and app to use with App Store Connect.
We cannot edit a synced configuration file unless we convert it to a local one.
2. Enabling StoreKit testing in Xcode
By default, StoreKit testing in Xcode is disabled. We can activate it by selecting the configuration file in the scheme editor:
To disable StoreKit testing, we can restore the default state by selecting none.
Test purchasing products
With a finished StoreKit testing setup, we can start testing our in-app purchasing code by purchasing products through our app. Every purchase will be simulated by Xcode.
After purchasing a product, we can use Xcode to manage transactions, for example to reset the purchase for testing purposes or to test a refund or a price increase.
We can open the transaction manager from the bottom buttons bar when the configuration file is open or from Xcode's menu Debug -> StoreKit -> Manage transactions.
Like to support my work?
Articles with related topics
How to restore in-app purchases with StoreKit 2 for iOS
Learn how to restore in-app purchases proactively and with a restore purchases button.
09 Oct 2023 · 2 min read
Get started with StoreKit 2 for iOS
Learn how to implement in-app purchases and subscriptions with StoreKit 2.
02 Oct 2023 · 4 min read
Quick tip on how to unit test Swift optionals with XCTUnwrap
Learn how to shorten if let and guard statements when unit testing.
06 Mar 2023 · 2 min read
Getting started with UI testing for SwiftUI
Learn how to create user interface tests with the XCTest framework.
30 May 2022 · 4 min read
Testing remote iOS push notifications in a simulator with simctl
Learn how to use the command-line tool simctl to simulate remote notifications in iOS.
25 Apr 2022 · 2 min read
Latest articles and tips
Introduction to Kotlin for Swift developers - protocols, extensions & generics
Learn how protocols, extensions and generics in Kotlin work from a Swift developer's point of view.
02 Dec 2023 · 8 min read
How to store images in SwiftData
Learn how to efficiently store larger amounts of data in SwiftData.
27 Nov 2023 · 1 min read
How to migrate to a new schema with SwiftData in iOS
Learn how to create a migration plan in SwiftData.
20 Nov 2023 · 4 min read
How to implemet a free trial period for StoreKit 2 subscriptions in iOS
Learn how to implement StoreKit 2 introductory offers.
13 Nov 2023 · 2 min read
How to migrate from Localizable.strings to String Catalogs
Learn how to migrate your iOS project to .xcstrings for localization.
06 Nov 2023 · 1 min read