I'm attempting to test error handling in my StoreKit implementation using SKTestSession.setSimulatedError(), but it doesn't trigger any errors. All StoreKit APIs (.loadProducts, .purchase, .appTransaction) succeed despite error simulation being configured before API calls.
According to Apple's documentation, setSimulatedError(_:forAPI:) should cause the specified API to throw an error, but this doesn't happen in my testing environment.
I found a previous forum discussion: "SKTestSession.setSimulatedError() not working for .loadProducts API in iOS 26.2" which mentioned this was a bug in iOS 26.2 and was supposedly fixed in iOS 26.3.
However, I'm experiencing the same issue in my current environment (Xcode 26.6 / iOS 26.5), which suggests either:
- The bug has regressed, or
- There's a different underlying issue, or
- I'm missing something in my implementation
I wanted to report this to confirm whether this is still a known issue or if additional steps are needed.
- Xcode: 26.6
- Test Environment: iOS Simulator - iPhone 17 Pro(26.5)
- Testing Framework: XCTest
- StoreKitTest Framework: Included in Xcode
import XCTest
import StoreKit
import StoreKitTest
final class StoreKitErrorTests: XCTestCase {
func test_LoadProducts_SetSimulatedError() async throws {
// Arrange
let session = try SKTestSession(configurationFileNamed: "storekit")
session.clearTransactions()
session.disableDialogs = true
// Set simulated error for loadProducts API
try await session.setSimulatedError(
.generic(.unknown),
forAPI: .loadProducts
)
// Act - Attempt to load products
do {
let products = try await Product.products(for: ["com.example.app.testproduct"])
// This line executes - products were loaded successfully
print("[TEST] FAIL: Loaded \(products.count) products")
XCTFail("setSimulatedError did not work - products loaded successfully")
} catch {
// This should execute, but it doesn't
print("[TEST] PASS: Error was thrown")
}
}
}
Note: Showing only the product definition. File also contains settings and version info.
{
"products" : [
{
"displayPrice" : "1.23",
"familyShareable" : false,
"internalID" : "5AE6F98A",
"localizations" : [
{
"description" : "Test app",
"displayName" : "LsStorekit",
"locale" : "en_US"
}
],
"productID" : "com.example.app.testproduct",
"referenceName" : "LsStorekit",
"type" : "NonConsumable"
}
]
}
The Product.products(for:) call should throw an error because setSimulatedError(.generic(.unknown), forAPI: .loadProducts) was called before the API invocation.
The test should:
- Configure the simulated error
- Attempt to load products
- Catch an error in the catch block
- Test passes with: "[TEST] PASS: Error was thrown"
Products are loaded successfully despite the error simulation:
• The do block completes without throwing
• 1 product is returned from Product.products(for:)
• XCTFail() is called, indicating the error simulation didn't work
• Test fails with: "[TEST] FAIL: Loaded 1 products"
[TEST] FAIL: Loaded 1 products
I've tested setSimulatedError with multiple APIs, and all show the same behavior:
| .loadProducts | .generic(.unknown) | No error thrown |
| .purchase | .generic(.unknown) | No error thrown |
| .appTransaction | .generic(.unknown) | No error thrown |
| .appStoreSync | .generic(.unknown) | No error thrown |
• Calling setSimulatedError before app launch (in UI tests)
• Calling setSimulatedError after app launch but before API calls
• Using different error types (.generic(.unknown), .generic(.networkError(...)))
• Testing in both Unit Tests and UI Tests
• Using different APIs (.loadProducts, .purchase, .appTransaction)
• Clearing transactions and resetting session state
• Verifying the .storekit file is correctly loaded (products load successfully)
• Running the app first (⌘R) to ensure StoreKit configuration is registered with the StoreKit daemon - This was necessary to fix an initial issue where products weren't loading at all
- Is this a known limitation of SKTestSession.setSimulatedError()?
- Are there additional steps required to make error simulation work?
- Is there an alternative approach to test StoreKit error handling?
- Does this work in specific Xcode/iOS SDK versions only?
Any guidance would be greatly appreciated. I need to test error handling in my StoreKit implementation, but cannot find a way to simulate errors reliably.