Skip to main content
Chappie ships a dedicated ChappieSDKTesting library target that provides seeded auth fixtures and an in-memory credential store for unit and UI tests. Keep it out of your app target — link it only to test targets so test-only code never ships to production.

Adding ChappieSDKTesting to your test target

Add the package dependency and link both ChappieSDK and ChappieSDKTesting to your test target in Package.swift:
If your tests also exercise thread storage or runtime events, add ChappieSDKRuntime to the same target:
Never link ChappieSDKTesting from your app target. It is designed exclusively for test and UI-test targets — linking it to your app would bundle test fixtures and Keychain helpers into your production binary.

Seeding a signed-in session

Call ChappieTestAuth.seedSignedInSession() at the start of a test to write a fake-but-valid credential into the Keychain so ChappieAuthSession starts in the .signedIn state without requiring a real OAuth flow:
The default seeded account uses these values:

Customising the seeded account

Pass a ChappieAccountInfo to override any account metadata fields:
Pass a custom keychainService when the app under test uses a non-default service name:

Clearing a seeded session

Call ChappieTestAuth.clearSession() in your test tear-down to remove the seeded credential and return the app to a signed-out state:
Pass the same custom service name if you used one when seeding:

Using ChappieInMemoryThreadStore in unit tests

For unit tests that exercise conversation storage without touching the filesystem, use ChappieInMemoryThreadStore from ChappieSDKRuntime. It implements the full ChappieThreadStore protocol in memory and applies the same retention logic as ChappieFileThreadStore:
Pass a custom now closure to test time-dependent retention behaviour without sleeping:

UI tests: resetting auth state via launch arguments

The demo app pattern shows how to handle auth state in UI tests using launch arguments. In your app’s @main entry point, check for the -resetChappieAuthForUITests launch argument (in a #if DEBUG block) and call ChappieTestAuth.clearSession() before creating the auth session:
Then pass the argument from your XCUIApplication setup in the UI test target:
Use -seedChappieAuthForUITests to start UI tests in the signed-in state without going through the actual OAuth flow.

Running the SDK’s test suite

Run all Swift package tests from the ChappieSDK directory:
Build the demo apps to verify the full project compiles: