StoreKit Testing with different Country Codes

I am writing unit tests that change the country by setting the .storefront property of SKTestSession to different country codes. I have made sure that the country codes I am using are indeed valid based on ISO 3166-1 alpha-3 region code standards.

My default storefront in the StoreKit Configuration file is "USA" but in the unit test, I set it to say "IND" and it runs my test. In the production code, when I print await Storefront.current?.countryCode, I indeed get "IND" as expected. Now when I change the value to say "RUS" by assigning it to the SKTestSession instance, the printed value in production code is still "IND" from the previous assignment.

If I call .resetToDefaultState() on the session after first test passes with "IND", it defaults to "USA" but when I set it to "RUS" in my test after it, it stays on "USA".

Basically the value does not change after the first change and calling reset resets it to configuration file default but reassigning a new value has no effect on Storefront.

What am I doing wrong?

Btw, I have tested with both XCTest and Swift Testing but the testing framework has nothing to do with this issue.

I am on Xcode 16, macOS 15, Swift 6

Here is my code

import StoreKit
import StoreKitTest
import Testing

@testable import StoreKitSwiftTesting

final class StoreKitSwiftTestingTests {
    // Intentionally setting to something different from StoreKit Config default "USA"
    enum Country: String, CaseIterable {
        case north = "CAN" 
        case south = "MEX"
    }

    let session: SKTestSession

    init() {
        session = try! SKTestSession(configurationFileNamed: "Store")  // Set default to "USA" in Store.storekit configuration file
        session.disableDialogs = true
    }

    deinit {
        session.resetToDefaultState()
        print("⛔️ session country: \(session.storefront) -- deinit")
    }

    @Test(.serialized, arguments: Country.allCases)
    func countryCode(for country: Country) async throws {
        print("✅ received country: \(country.rawValue)")

        session.storefront = country.rawValue
        print("\(session.storefront == country.rawValue ? "✅" : "❌") country on session: \(session.storefront)")

        let countryCode = try #require(await Storefront.current?.countryCode)
        print("\(countryCode == country.rawValue ? "✅" : "❌") Storefront Country: \(countryCode)")
        #expect(countryCode == country.rawValue)
    }
}

Here is the stdout

◇ Test run started.
↳ Testing Library Version: 94 (arm64-apple-ios13.0-simulator)
◇ Suite StoreKitSwiftTestingTests started.
◇ Test countryCode(for:) started.
◇ Passing 1 argument country → .north to countryCode(for:)
✅ received country: CAN
✅ country on session: CAN
✅ Storefront Country: CAN
⛔️ session country: USA -- deinit
​◇ Passing 1 argument country → .south to countryCode(for:)
✅ received country: MEX
✅ country on session: MEX
❌ Storefront Country: USA
✘ Test countryCode(for:) recorded an issue with 1 argument country → .south at StoreKitSwiftTestingTests.swift:41:9: Expectation failed: (countryCode → "USA") == (country.rawValue → "MEX")
⛔️ session country: USA -- deinit
​✘ Test countryCode(for:) failed after 0.027 seconds with 1 issue.
✘ Suite StoreKitSwiftTestingTests failed after 0.027 seconds with 1 issue.
✘ Test run with 1 test failed after 0.027 seconds with 1 issue.

As you can see the first run of the test function seems as expected, it prints "CAN" for all print statements which is correct. When the first run completes, the deinit gets called which resets the session. Resetting the session causes session to get values from the storekit config file which has "USA". But in the second run of the test function with param value of "MEX", it does not change the Storefront countryCode but instead keeps it to reset default "USA"

Please file a bug report about your issue then post the Feedback number here.

Filed at the same time of posting this. Sorry, didn’t paste the ID earlier. FB15309950

StoreKit Testing with different Country Codes
 
 
Q