How to Test In-App Purchases in Flutter

· 6 min read

In-app purchases are the code path you can least afford to get wrong and the hardest to test. Real money, two stores, renewals that happen while the app is closed. The fix is to test in layers, from fast and local to slow and realistic.

This guide covers each layer for a Flutter app on iOS and Android. It assumes you have the purchase flow in place; if not, start with Flutter in-app purchase with StoreKit 2. For the whole app path, see the guide to building a Flutter app with Claude Code.

The four layers

Layer Platform Needs store setup Best for
StoreKit Testing in Xcode iOS No Fast iteration, edge cases
Sandbox from Xcode iOS Yes Real product data
TestFlight iOS Yes Release builds, testers
License testers Android Yes Billing on debug and track builds

Work down the table. Each layer catches bugs the previous one cannot.

Layer 1: StoreKit Testing in Xcode

Apple calls this “a local test environment for testing in-app purchases without requiring a connection to App Store servers.” You describe products in a .storekit file and StoreKit uses that data instead of App Store Connect.

Apple lists what it is good for, including:

  • “Developing features that use in-app purchases before configuring them in App Store Connect.”
  • “Testing locally when a network connection isn’t available.”
  • “Testing transactions end-to-end, including failed transactions.”

Set it up:

  1. Open ios/Runner.xcworkspace in Xcode.
  2. Choose File, New, File from Template, type “storekit” in the filter and pick StoreKit Configuration File.
  3. Leave the sync checkbox off for a local file, or turn it on to sync products you already created in App Store Connect.
  4. Add your products with the same product IDs your Dart code requests.
  5. Edit the Runner scheme, select the Run action, open Options and set StoreKit Configuration to your file.

By default StoreKit Testing is disabled, and only one configuration file can be active at a time. The setting lives in the Xcode scheme, so launch the app from Xcode when you want the local data. Prices in the file are placeholders that “don’t upload to App Store Connect.”

Because in_app_purchase uses StoreKit 2 by default on iOS, your Flutter code talks to this test environment without any changes.

Layer 2: Apple sandbox

The sandbox uses real product information from App Store Connect but “without processing actual payments.” It applies to development-signed apps you run from Xcode and to apps from TestFlight.

Before it works, Apple requires:

  • an active Developer Program account,
  • the Paid Applications Agreement signed by the Account Holder,
  • products set up with at least “a product reference name, product ID, a localized name, and a price,”
  • Sandbox Apple Accounts created in App Store Connect.

Sign in on the device. For a development build, the sandbox account appears in Settings, Developer, after you first attempt a purchase. You do not need to sign out of your normal Apple Account. When you sign in to buy, look for [Environment: Sandbox]. Apple says if it does not appear, “you’re using the production environment.”

Useful sandbox settings. From App Store Connect or from Settings, Developer, Manage on the device, you can change the subscription renewal rate, enable interrupted purchases and clear purchase history. Clearing history makes the account eligible for introductory offers again, which is the easy way to retest a free trial. Changing the storefront country is only available in App Store Connect.

One note from Apple to save you a debugging session: changes to product metadata “can take up to one hour to appear in the sandbox environment.”

Layer 3: TestFlight

“Apps that you download from TestFlight always run in the sandbox environment.” That makes TestFlight the closest you get to production on iOS: a release build, real product data and no charges.

To use the sandbox controls with a TestFlight build, Apple’s steps are to sign out of Media & Purchases in your Apple Account settings, then sign in with a Sandbox Apple Account under Settings, Developer. Apple warns this can remove access to content you bought in production apps, so a dedicated test device helps.

For adding testers, see App Store Connect: add testers and TestFlight internal vs external testing.

Layer 4: Google Play license testers

On Android, the Billing Library is normally “blocked for apps that aren’t signed and uploaded to Google Play.” License testers bypass that check, so you can sideload a debug build, as long as the package name matches the app in Play Console and the Google Account is a license tester.

License testers also get test payment methods:

  • Test card, always approves for the happy path,
  • Test card, always declines for failed payments,
  • Slow test card, approves after a few minutes and Slow test card, declines after a few minutes for pending purchases.

Fast renewals. Test subscriptions renew quickly and “can renew a maximum of six times”:

Real period Test renewal
1 week 5 minutes
1 month 5 minutes
3 months 10 minutes
6 months 15 minutes
1 year 30 minutes

Free trials last 3 minutes, grace periods 5 minutes and account hold 10 minutes.

Acknowledgement check. For license testers, a purchase is “refunded after 3 minutes if your app does not acknowledge the purchase.” In Flutter, that means you forgot completePurchase. Check the Orders tab in Play Console if purchases silently disappear.

Play Billing Lab is a separate Android app for license testers. It can change the Play country, let you repeat trial offers with the same account and move a test subscription into grace period or account hold.

For distributing Android test builds, see Google Play closed vs internal testing. Note that Google applies spend limits to draft apps and internal test track releases.

A test plan that covers the real cases

Run each of these on both platforms before release:

  1. Buy each product with the approving test card or sandbox account.
  2. Cancel from the store sheet. The UI must reset, with no error dialog.
  3. Use a declining card. No access granted.
  4. Use a slow card. Show a pending state, then grant or deny later, even after an app restart.
  5. Kill the app right after paying. On relaunch, the purchase stream must deliver and grant it.
  6. Restore on a fresh install.
  7. Let a subscription renew several times, then expire. Access must end.
  8. Retest the free trial after clearing history (iOS) or using Play Billing Lab (Android).

Google also recommends occasional tests with accounts that are not license testers, so your app “does not rely on testing specific logic such as renewal durations.”

This plan also makes good prep for store review. See guideline 3.1.1 in-app purchase and the Google Play subscriptions policy. MobileKit’s QA skill runs a version of this checklist for you.

Sources read on the day this post was written: Apple: setting up StoreKit Testing in Xcode, Apple: testing in-app purchases with sandbox, Google Play Billing: test your integration and in_app_purchase on pub.dev.

Questions

Can I test Google Play purchases with a debug build?

Yes, with a license tester. Google says license testers can bypass the check that blocks billing for apps not signed and uploaded to Google Play, as long as the package name matches the app configured in Play Console.

How fast do test subscriptions renew on Google Play?

Google lists a 1 week or 1 month subscription renewing every 5 minutes, 3 months every 10 minutes, 6 months every 15 minutes and 1 year every 30 minutes. Test subscriptions renew a maximum of six times.

Do TestFlight purchases charge real money?

No. Apple says apps downloaded from TestFlight always run in the sandbox environment, where transactions do not incur charges.

Try it on your next idea

One payment, every update to this major version, and a refund window if it is not for you. Refund policy.