Logo for tanaschita.com

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.

Sponsorship logo
Capture HTTP(s) traffic with Proxyman
Proxyman - Your ultimate man-in-the-middle proxy to effortlessly capture, inspect, and manipulate HTTP(s) traffic on macOS, Windows, iOS, and Android devices.
Get started for free

Overview

To setup StoreKit testing in Xcode, the following steps are required:

  1. Creating and configuring a StoreKit configuration file.
  2. Enabling StoreKit testing in Xcode.
  3. 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:

StoreKit configuration file
StoreKit configuration file.

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.

Locally configure in-app purchase options.
Locally configure in-app purchase options.

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.

Using synced configuration files.
Adding a synced StoreKit configuration file.

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:

Enabling StoreKit testing in Xcode.
Enabling StoreKit testing in Xcode.

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.

Xcode's transaction manager
Xcode's transaction manager

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.

Sponsorship logo
Capture HTTP(s) traffic with Proxyman
Proxyman - Your ultimate man-in-the-middle proxy to effortlessly capture, inspect, and manipulate HTTP(s) traffic on macOS, Windows, iOS, and Android devices.
Get started for free

Newsletter

Image of a reading marmot
Subscribe

Like to support my work?

Say hi

Related tags

Articles with related topics

testing

swift

ios

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

Latest articles and tips

© 2023 tanaschita.com

Privacy policy

Impressum