StoreKitTest : Request product error Domain=ASDErrorDomain Code=950 "Unhandled exception"

946 Views Asked by At

I'm trying to unit test my framework calling StoreKit with the new (iOS 14) StoreKitTest and I'm getting this error when I fetch products :

Error Domain=SKErrorDomain Code=0 "UNKNOWN_ERROR" UserInfo={NSLocalizedDescription=UNKNOWN_ERROR, NSUnderlyingError=0x7fab74623870 {Error Domain=ASDErrorDomain Code=950 "Unhandled exception" UserInfo={NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}}}

This is my code :

import XCTest
import StoreKitTest

class FrutaTests: XCTestCase {

    var session: SKTestSession!
    var request: SKProductsRequest!
    var expectation: XCTestExpectation?

    override func setUpWithError() throws {
        session = try SKTestSession(configurationFileNamed: "Configuration")
    }

    override func tearDownWithError() throws {
        session = nil
    }

    func testFetchProducts() throws {
        let productIdentifiers = Set<String>()

        expectation = XCTestExpectation(description: "fetchProducts")

        request = SKProductsRequest(productIdentifiers: productIdentifiers)

        request.delegate = self

        request.start()

        wait(for: [expectation!], timeout: 10.0)
    }
}

extension FrutaTests: SKProductsRequestDelegate {
    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
        print(response.products.map({$0.productIdentifier}))

        expectation?.fulfill()
    }

    func requestDidFinish(_ request: SKRequest) {
        print("DidFinishh")
    }

    func request(_ request: SKRequest, didFailWithError error: Error) {
        print(error)
    }
}
1

There are 1 best solutions below

0
On BEST ANSWER

I found where the error came from : In my test target, in General, I'd removed Host Application because I didn't want the app to compile and unchecked the Allow testing Host Application APIs.

It seems that StoreKitTest requires this setting but the error is really unclear!