SKTestSession testing failures
With iOS 17, Apple shipped a new API allows us to simulate errors when unit testing StoreKit. The API exposes a method called
setSimulatedError
For example, we would use the API to simulate a NetworkError for the purchase API.
try await session.setSimulatedError(.generic(.networkError(URLError(.badURL, userInfo: [:]))), forAPI: .purchase)
This is a great addition and it allows us to test possible error handling flows we have in our code. One thing I encountered when working with this API is that the simulated errors would persist even if I called
try await session.setSimulatedError(nil, forAPI: .purchase)
as outlined in the WWDC session.
The current workaround for this is to call the resetToDefaultState
method on the session before each test executes.
session.resetToDefaultState()
Until next time, M.
- ← Previous
Attaching debugger to system apps