Design and Run Test Cases for IAP
Amazon provides the App Tester tool to unit test your app before you submit it to the Appstore. To effectively test your app, create a set of test cases that will give you comprehensive coverage for the various scenarios that users will encounter when interacting with your app.
Your app's interaction with the Amazon Appstore is isolated to the API libraries, so your app will not know that it is talking with App Tester. Because you have control over the responses given by the App Tester, you can test your app's behavior under any response condition.
This page describes a set of test cases that should cover most user scenarios for your app's implementation of IAP and discusses how to run those test cases using App Tester. For information more information about App Tester, see the following pages:
- Summary of Test Cases
- Get User Data
- Get Product Data
- Purchase
- Purchase Updates Request
- Notify Fulfillment
- Subscription Check
- Verify Receipts
- IAP Response Matrix
Summary of Test Cases
When you are testing the IAP implementation in your app, plan your test cases to cover as many code paths as possible. The following list of transaction types should give you good coverage for the various scenarios that you might expect to encounter with your app's users:
- Get User Data (Successful/Failed)
- Get Product Data (Successful/Failed)
- Purchase Request (Successful/Failed/Already purchased/Invalid SKU)
- Purchase Updates Request (Successful/Failed)
- NotifyFulfillment (Successful/Unavailable)
- Subscription Check (Valid/Expired)
- Verify Receipts (RVS)
Get User Data
Both the Amazon Appstore and App Tester tool track transactions by User ID. Because your app should be able to handle multiple users at a time, any user-specific function in the app should check the current logged-in User ID at the appropriate points, such as the Android lifecycle method onResume()
. When retrieving user data, you can receive either a SUCCESSFUL or FAILED response.
To test Get User Data for either response:
- In App Tester, go to the User Account Settings tab, and make sure that the User ID is set.
- Set the GetUserData API Preference:
- To test for a SUCCESSFUL response, set the preference to DEFAULT or SUCCESSFUL.
- To test for a FAILED response, set the preference to FAILED.
- Call
getUserData
. - Process the response using
onGetUserDataResponse
.
Get Product Data
When performing a test for Get Product Data, the App Tester will return product data from the JSON file in DEFAULT mode. When retrieving product data, you can receive either a SUCCESSFUL or FAILED response.
To test Get Product Data:
- Verify that your JSON file for App Tester contains the SKUs and product definitions that you want to test.
- Set the GetProductData API Preference:
- To test for a SUCCESSFUL response, set the preference to DEFAULT or SUCCESSFUL.
- To test for a FAILED response, set the preference to FAILED.
- Call
getProductData
. - Process the response using
onGetProductDataResponse
.
Purchase
To simplify implementation and testing, the Purchase API works identically for all three types of IAP items:
- Subscriptions: One-time purchase by a user
- Entitlements: One-time purchase by a user
- Consumables: Can be purchased multiple times by the same user
To test the Purchase API:
- Verify that your JSON file for App Tester contains the SKUs and product definitions that you want to test.
- Set the Purchase API Preference. Make sure to test each of the four available conditions:
- To test for a SUCCESSFUL response, set the preference to DEFAULT or SUCCESSFUL.
- To test for a FAILED response, set the preference to FAILED.
- To test for an ALREADY_PURCHASED request, set the preference to ALREADY_PURCHASED.
- To test for an INVALID_SKU, set the preference to INVALID_SKU.
- Call
purchase
. - Process the response using
onPurchaseResponse
.
Successfully purchased content will appear on the App Tester's Manage Transactions tab.
Alternately, you can test the "already purchased" condition by progressing through a typical purchase workflow:
- Verify that your JSON file for App Tester contains the SKUs and product definitions that you want to test.
- Set the Purchase API Preference to DEFAULT.
- Make a successful purchase for a subscription or entitlement SKU. (Consumables may be purchased multiple times.)
- Call
purchase
again using the same SKU. - Process the response using
onPurchaseResponse
.
Successfully purchased content will appear on the App Tester's Manage Transactions tab.
Purchase Updates Request
To ensure that a user has access to their correct content, call the Purchase Update Requests API when your app starts interacting with that user (in the onResume()
method of the Android lifecycle), Successful responses can include zero or many receipts from previous transactions, depending on the contents of the Manage Transactions tab in the App Tester.
You can verify tokens present in the receipts using the Receipt Verification Service (RVS).
To test Purchase Update Requests:
- Verify that your JSON file for App Tester contains the SKUs and product definitions that you want to test.
-
Successfully purchase the SKUs that you configured.
- Set the GetPurcaseUpdates API Preference:
- To test for a SUCCESSFUL response, set the preference to DEFAULT or SUCCESSFUL.
- To test for a FAILED response, set the preference to FAILED.
- Call
getPurchaseUpdates
. - Process the response using
onPurchaseUpdatesResponse
.
If you want to generate a SUCCESSFUL but empty response, use the following workflow:
- Verify that your JSON file for App Tester contains the SKUs and product definitions that you want to test.
- Successfully purchase the SKUs that you configured.
- Set the getPurchaseUpdates API Preference to DEFAULT.
- On the Manage Transactions tab, delete all transactions.
- Call
getPurchaseUpdates
. - Process the response using
onPurchaseUpdatesResponse
.
Notify Fulfillment
Call the Notify Fulfillment API to verify fulfillment and test for the available receipt states in IAP. You can use the following workflow to test fulfillment for Consumable or Entitlement items.
To test Notify Fulfillment:
- Call
purchase
for a consumable item. - Note the receipt for the purchased item.
- Call
getPurchaseUpdate
. - Note the returned consumable receipt.
- In App Tester, on the Manage Transactions tab, verify that the consumable is set to be delivered.
- Call
notifyFullfilment
:- To test the "fulfilled" condition, set
notifyFulfillment
to SUCCESSFUL. - To test the "unavailable" condition, set
notifyFulfillment
to UNAVAILABLE.
- To test the "fulfilled" condition, set
- In App Tester, verify the purchase on theh Manage Transactions tab:
- If you are testing the "fulfilled" condition, the consumable should be listed as Fulfilled.
- If you are testing the "unavailable" condition, the consumable should be listed as Unavailable.
Subscription Check
You can use App Tester to verify both valid and expired subscriptions. If you cancel an active subscription transaction from the Manage Transactions tab, App Tester treats that transaction as an expired subscription.
To test for a valid subscription:
- Make a successful purchase of a subscription SKU.
- Go to the Manage Transactions tab, and verify that the transaction is listed there.
- Call
getPurchaseUpdates
. - Process the response using
onPurchaseUpdatesResponse
. - From the returned receipts, verify that the most recent receipt (by start date) for the SKU that you purchased.
- Verify that the value of the end date is null.
To test for an expired subscription:
- Make a successful purchase of a subscription SKU.
- Go to the Manage Transactions tab, and verify that the transaction is listed there.
-
On the Manage Transactions tab, cancel the transaction.
- Call
getPurchaseUpdates
. - Process the response using
onPurchaseUpdatesResponse
. - From the returned receipts, verify that the most recent receipt (by start date) for the SKU that you purchased.
- Verify that the value of the end date is not null.
Verify Receipts
Amazon provides a Receipt Verification Service (RVS), which you can use to validate purchases from your back-end server. To learn more about this service, see Receipt Verification Service Overview.
IAP Response Matrix
The following matrix maps IAP API responses to their App Tester properties and other testing conditions:
IAP API Response | Async Invocation | AppTester Property Set | JSON Used? | Notes |
---|---|---|---|---|
PurchaseRequestStatus. SUCCESSFUL | purchase | Purchase API, DEFAULT or SUCCESSFUL | Yes | As long as the purchase is for a valid SKU in the JSON file, a successful response is returned |
PurchaseRequestStatus. FAILED | purchase | Purchase API, FAILED | Yes (to display item information) | The App Tester Forces a Failed response when this property is set to FAILED in Preference Page or if the Purchase Confirmation Dialog is closed |
PurchaseRequestStatus. INVALID_SKU | purchase | Purchase API, INVALID_SKU | No | The App Tester Forces any Purchase Request to return INVALID_SKU when this property is set in Preference Page |
PurchaseRequestStatus. ALREADY_PURCHASED | purchase | Purchase API, ALREADY_PURCHASED | Yes | The App Tester Forces any Purchase Request to return ALREADY_PURCHASED when this property is set to ALREADY_PURCHASED in the API Response Settings tab or SKU has been purchased before |
GetProductDataStatus. SUCCESSFUL | getProductData | Get Product Data API, DEFAULT or SUCCESSFUL | Yes | As long as the request is for a valid SKU in the JSON file, a successful response is returned |
GetProductDataStatus. FAILED | getProductData | Get Product Data API, FAILED | No | App Tester Forces any Product Data Request to return FAILED when this property is set |
GetUserDataStatus. SUCCESS | getUserData | Get User Data API, DEFAULT or SUCCESSFUL | No | The App Tester will always return the User Id stored in the App Tester when this property is set in the API Response Settings tab |
GetUserIdRequestStatus. FAILED | getUserData | Get User Data API, FAILED | No | The App Tester forces a failed response when this property is set in the API Response Settings tab |
PurchaseUpdatesResponseStatus. SUCCESS | getPurchaseUpdates | Purchase Updates API, SUCCESSFUL | No | The App Tester will always return what is in the Transaction log when this property is set in the API Response Settings tab |
PurchaseUpdatesResponseStatus. FAILED | getPurchaseUpdates | Purchase Updates API, FAILED | No | The App Tester will force a failed response when this property is set in the API Response Settings tab |
Last updated: May 22, 2024