Skip to content
AppDues
Log in
Contact salesSign up

A Layered Testing Strategy for an iOS Subscription SDK

Purchases are unforgiving: a broken unlock or a failed renewal shows up as a support ticket, not a stack trace. A subscription SDK therefore needs more than one kind of test. Each layer answers a different question, and together they keep a release from reaching users with a defect that a cheaper check could have caught.

Why one test suite is not enough

A single test type tends to be good at one thing and blind to the rest. Fast unit tests pinpoint a faulty line but say nothing about whether the real backend accepts the request. A test against a live server proves the round trip works but struggles to explain which branch failed. Installation checks catch packaging problems that never appear in a normal development loop. The practical approach is to assign each suite a narrow job and let the combination cover the release path.

A useful way to think about it: ask what class of failure each suite can detect, and what it cannot. If two suites claim the same failure class, one of them is probably redundant. If a failure class has no owner, that is where a bug will eventually escape.

Unit tests: fast, specific, run constantly

Unit tests exist to point at a precise piece of code when something breaks. The working rule is that each unit of code is exercised independently, with a matching test class covering the internal and public methods of each class. Private methods are not tested directly, because their behavior should be observable through the class interface. When a private method becomes too complex to reach that way, the usual fix is to extract it into its own class rather than to test around the interface.

Speed matters here. A suite that runs in a second or two can be executed continuously during development, which makes refactoring safer. In CI the same tests are replayed across several OS versions and platforms so that an implementation that works on a recent OS does not silently break on an older one.

Snapshot testing fills a gap for large string-based structures that are awkward to assert field by field. Capturing a baseline JSON file and comparing against it is a compact way to confirm that the payload sent to the backend has not drifted.

StoreKit tests: exercising the real purchase types

StoreKit behavior is hard to fake faithfully. Before Apple shipped the StoreKit Test Framework, automated purchase tests depended on hand-built mocks, and some scenarios could not be covered at all. With StoreKit Test, tests can drive specific StoreKit configuration files and exercise the SDK against real StoreKit types.

This matters most for StoreKit 2, whose types cannot be mocked. A test that uses the genuine types through a configuration file is the only way to verify that path with automation. Treat this suite as the bridge between pure logic tests and anything that touches the store.

Backend integration tests: the real round trip

These tests run a real app against a real backend server rather than mocks or stubbed network calls. The questions they answer are concrete: does a purchase unlock the correct entitlement, and do renewals and expirations show up correctly in the SDK?

They are cheap to write and effective at catching defects, but they are poor at localization. A failing integration test can report that an entitlement was not unlocked after a purchase without saying why. The matching unit test is what narrows the cause, for instance to the logic that parses entitlements out of an HTTP JSON response. Run integration tests in CI for every commit that does not originate from a fork.

Installation tests: every supported way in

An SDK can pass every logic test and still fail to install. Packaging depends on build-system details: Swift Package Manager reads a Package.swift manifest, CocoaPods reads a Podspec, and Carthage relies on the Xcode project plus specific build settings to include dSYMs in the XCFramework. A folder reorganization or a new build requirement can break one path while the others keep working, and normal development rarely reinstalls through all of them.

Installation tests close that gap by installing the SDK into a sample app through each supported route, then building and running a small app that makes one SDK call. A successful call with the expected output confirms that route works. These tests deliberately do not exercise the SDK deeply; their scope is building and installing, not feature behavior.

Supported installation routes to cover:

  • Swift Package Manager
  • CocoaPods
  • Carthage with XCFrameworks
  • Carthage with regular frameworks
  • Adding the .xcodeproj file directly
  • Copying the XCFramework from the releases page
  • Copying the framework from the releases page

Run this suite on release branches.

API tests: guarding the public surface

The public API is the contract with every integrating app, so an unintended change can break compilation for a large number of projects. The guard is simple and effective: two small apps, one in Objective-C and one in Swift, that call every method and read every public property. If the public surface changes, those apps stop building and the change is visible immediately.

This kind of guard earns its keep during large internal changes. When a codebase moves to a different implementation language, the testers confirm that the interface still resolves to the same public shape for callers.

Documentation tests: keeping references honest

Documentation drifts quietly. A renamed method leaves a stale reference, and readers follow a link that no longer resolves. Enabling Xcode's build-documentation-during-build setting makes DocC generation part of the build, so an incorrect method name surfaces as a build warning instead of a broken page.

The goal is not just correct spelling but useful cross-references. Related types should point at each other: documentation for customer information should lead to the methods that fetch it, and both should link to the entitlement types a reader is likely to use alongside them.

The testing app: where a UI is required

Some behavior cannot be automated through a test harness. The testing app exists for those cases, and it remains useful even after StoreKit Test removed the original reason for building it. Features that open a subscription management screen or start a refund request need a real interface to be exercised.

The app supports two modes, Sandbox and StoreKit Configuration Files, which together cover realistic behavior across most use cases. It also serves as a place to try a feature the way a customer would, and it can be uploaded to TestFlight when needed. The trade-off is manual effort: this suite cannot be automated as readily as the others, which is why it is reserved for scenarios where a UI is the point.

Human review before a big release

Automation does not replace judgment about naming, documentation clarity, or the feel of a flow. Before a large feature ships, a testing party brings together colleagues from across the company, not only the SDK team, to try the feature and report back. Feedback ranges from a method name that does not read intuitively to confusing documentation, and sometimes includes defects the automated suites missed. The usual outcome is a concrete list of improvements to make before release.

A second signal comes from team members who also ship their own apps. Asking them to try a near-final feature in a real published app gives an early view of production behavior. A third comes from customers who opt in to betas, often after requesting the feature; their willingness to test early builds provides feedback from outside the company.

A checklist for assigning each failure class

Use this to decide where a new test belongs, and to spot gaps.

  • Logic error in a single class, no network involved: unit test.
  • Purchase flow that depends on genuine StoreKit types: StoreKit test with a configuration file.
  • Entitlement unlock or renewal reflected incorrectly end to end: backend integration test.
  • SDK fails to resolve or build after installation: installation test.
  • Source-compatibility break for integrating apps: API tester build.
  • Broken or stale documentation reference: documentation build.
  • Behavior that only appears with a real interface: testing app.
  • Naming, clarity, or UX concerns: testing party and beta feedback.

A worked example shows how the layers combine. Suppose a purchase completes but the entitlement does not unlock. The backend integration test reports the failure but cannot explain it. The unit test for the code that parses entitlements from the HTTP JSON response points at the specific faulty logic. The integration test proves the symptom is real; the unit test locates the cause. Neither alone gives the full picture.

What the investment buys

Building this many suites takes real effort up front. The return is that most testing becomes automatic, leaving development time for new features instead of manual verification. Releases can move quickly while remaining dependable across OS versions and platforms.

Open-source SDK repositories make it possible for outside contributors to suggest improvements to the test suites themselves, which is a useful channel for catching blind spots.

Frequently asked questions

When should a check be a unit test rather than a backend integration test?

If the question is whether a specific piece of logic behaves correctly in isolation, use a unit test. If the question is whether the SDK and a real server agree end to end, use an integration test. Integration tests confirm symptoms; unit tests locate causes.

Why use StoreKit configuration files instead of mocks?

StoreKit 2 types cannot be mocked, so a configuration file is the only way to exercise the real types in an automated test. Configuration files also let tests cover purchase scenarios that would otherwise be impossible to reproduce.

Do installation tests verify SDK features?

No. They install the SDK through each supported route, build a small app, and make one call to confirm the route works. Feature behavior is covered by the other suites.

What are the testing app's two modes?

Sandbox and StoreKit Configuration Files. Together they allow realistic testing across most use cases, including features that require a real interface.