<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "StoreKitTest",
  "identifier" : "/documentation/StoreKitTest/SKTestSession",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "StoreKit Test"
    ],
    "preciseIdentifier" : "c:objc(cs)SKTestSession"
  },
  "title" : "SKTestSession"
}
-->

# SKTestSession

The controls and environment configuration you use to test StoreKit transactions in Xcode.

```
class SKTestSession
```

## Overview

This class controls the settings that the server uses when it processes transactions. Run tests that reconfigure the environment serially, not concurrently, to avoid overwriting each other’s environment settings.

> Note:
> There’s a single instance of the test environment. All `SKTestSession` instances control the same test environment.

The test environment creates an [`SKTestTransaction`](/documentation/StoreKitTest/SKTestTransaction) instance each time your test code calls any method of `SKTestSession` that affects in-app purchases, including:

- [`buyProduct(productIdentifier:)`](/documentation/StoreKitTest/SKTestSession/buyProduct(productIdentifier:))
- [`refundTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/refundTransaction(identifier:))
- [`enableAutoRenewForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/enableAutoRenewForTransaction(identifier:))
- [`disableAutoRenewForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/disableAutoRenewForTransaction(identifier:))
- [`forceRenewalOfSubscription(productIdentifier:)`](/documentation/StoreKitTest/SKTestSession/forceRenewalOfSubscription(productIdentifier:))
- [`expireSubscription(productIdentifier:)`](/documentation/StoreKitTest/SKTestSession/expireSubscription(productIdentifier:))
- [`approveAskToBuyTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/approveAskToBuyTransaction(identifier:))
- [`declineAskToBuyTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/declineAskToBuyTransaction(identifier:))
- [`resolveIssueForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/resolveIssueForTransaction(identifier:))

You can manage the transactions in the test environment. To get a list of all transactions in the test environment, call [`allTransactions()`](/documentation/StoreKitTest/SKTestSession/allTransactions()). To delete a single transaction, call [`deleteTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/deleteTransaction(identifier:)). To delete all the transactions, call [`clearTransactions()`](/documentation/StoreKitTest/SKTestSession/clearTransactions()).

Before automating a test session with `SKTestSession`, you must create a StoreKit configuration file. For more information, see <doc://com.apple.documentation/documentation/Xcode/setting-up-storekit-testing-in-xcode> and [`init(configurationFileNamed:)`](/documentation/StoreKitTest/SKTestSession/init(configurationFileNamed:)). Set [`disableDialogs`](/documentation/StoreKitTest/SKTestSession/disableDialogs) to `true` to run tests without showing test environment UI.

## Topics

### Initializing test sessions

[`init(configurationFileNamed:)`](/documentation/StoreKitTest/SKTestSession/init(configurationFileNamed:))

Initializes the test session with the provided configuration file that you include in your application’s bundle.

[`init(contentsOf:)`](/documentation/StoreKitTest/SKTestSession/init(contentsOf:))

Initializes the test session with a configuration file you provide through a URL.

[`resetToDefaultState()`](/documentation/StoreKitTest/SKTestSession/resetToDefaultState())

Removes all property overrides and resets all test session settings to their default state.

### Configuring the test environment

[`storefront`](/documentation/StoreKitTest/SKTestSession/storefront)

The three-letter code that represents the region associated with the App Store storefront.

[`locale`](/documentation/StoreKitTest/SKTestSession/locale)

The value that determines the localization metadata the test environment uses.

[`disableDialogs`](/documentation/StoreKitTest/SKTestSession/disableDialogs)

A Boolean value that determines whether the testing environment disables dialogs during automated testing.

### Managing transactions in the test environment

[`allTransactions()`](/documentation/StoreKitTest/SKTestSession/allTransactions())

Gets a list of all transactions in the test environment.

[`deleteTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/deleteTransaction(identifier:))

Deletes a specific transaction from the test environment.

[`clearTransactions()`](/documentation/StoreKitTest/SKTestSession/clearTransactions())

Removes all transactions from the test environment.

### Forcing failed transactions

[`failTransactionsEnabled`](/documentation/StoreKitTest/SKTestSession/failTransactionsEnabled)

A Boolean value that determines whether transactions fail in the testing environment.

[`failureError`](/documentation/StoreKitTest/SKTestSession/failureError)

The error code that transactions return when you enable failing transactions.

### Testing interrupted purchases

[`interruptedPurchasesEnabled`](/documentation/StoreKitTest/SKTestSession/interruptedPurchasesEnabled)

A Boolean value that determines whether the test environment simulates an interrupted purchase.

[`resolveIssueForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/resolveIssueForTransaction(identifier:))

Simulates resolving an issue when you test interrupted purchases or billing retry scenarios.

### Testing Ask To Buy transactions

[`askToBuyEnabled`](/documentation/StoreKitTest/SKTestSession/askToBuyEnabled)

A Boolean value that determines whether the testing environment simulates an Ask to Buy scenario.

[`approveAskToBuyTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/approveAskToBuyTransaction(identifier:))

Resolves an Ask to Buy test scenario by approving the transaction.

[`declineAskToBuyTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/declineAskToBuyTransaction(identifier:))

Resolves an Ask to Buy test scenario by declining the transaction.

### Testing subscription renewals

[`timeRate`](/documentation/StoreKitTest/SKTestSession/timeRate-swift.property)

The rate at which time passes for subscriptions in the test environment as compared to real time.

[`SKTestSession.TimeRate`](/documentation/StoreKitTest/SKTestSession/TimeRate-swift.enum)

The values for rates of time passing in the test environment.

[`enableAutoRenewForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/enableAutoRenewForTransaction(identifier:))

Enables auto-renewing for an auto-renewable subscription in the test environment.

[`disableAutoRenewForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/disableAutoRenewForTransaction(identifier:))

Disables auto-renewing for an auto-renewable subscription in the test environment.

[`forceRenewalOfSubscription(productIdentifier:)`](/documentation/StoreKitTest/SKTestSession/forceRenewalOfSubscription(productIdentifier:))

Ends the previous subscription period and begins the next period in the test environment.

[`expireSubscription(productIdentifier:)`](/documentation/StoreKitTest/SKTestSession/expireSubscription(productIdentifier:))

Causes the identified auto-renewable subscription to expire immediately in the test environment.

### Testing billing retry and grace period

[`billingGracePeriodIsEnabled`](/documentation/StoreKitTest/SKTestSession/billingGracePeriodIsEnabled)

A Boolean value that indicates whether the test environment simulates a billing grace period for auto-renewable subscriptions.

[`shouldEnterBillingRetryOnRenewal`](/documentation/StoreKitTest/SKTestSession/shouldEnterBillingRetryOnRenewal)

A Boolean value that indicates whether the testing environment enters a billing retry state when an auto-renewable subscription renews.

[`resolveIssueForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/resolveIssueForTransaction(identifier:))

Simulates resolving an issue when you test interrupted purchases or billing retry scenarios.

### Testing price increase consent

[`requestPriceIncreaseConsentForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/requestPriceIncreaseConsentForTransaction(identifier:))

Simulates a price increase that requires customer consent for an auto-renewable subscription.

[`consentToPriceIncreaseForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/consentToPriceIncreaseForTransaction(identifier:))

Simulates a user consenting to a price increase for an auto-renewable subscription.

[`declinePriceIncreaseForTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/declinePriceIncreaseForTransaction(identifier:))

Simulates a user canceling an auto-renewable subscription by disabling auto-renew.

### Testing externally performed transactions

[`buyProduct(productIdentifier:)`](/documentation/StoreKitTest/SKTestSession/buyProduct(productIdentifier:))

Simulates buying an in-app purchase or subscription outside the app.

[`refundTransaction(identifier:)`](/documentation/StoreKitTest/SKTestSession/refundTransaction(identifier:))

Simulates a refund for an in-app purchase that completes outside of the app.

### Instance Methods

[`buyProduct(identifier:options:)`](/documentation/StoreKitTest/SKTestSession/buyProduct(identifier:options:))

[`setSimulatedError(_:forAPI:)`](/documentation/StoreKitTest/SKTestSession/setSimulatedError(_:forAPI:))

[`simulatedError(forAPI:)`](/documentation/StoreKitTest/SKTestSession/simulatedError(forAPI:))



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)