CoproductTestHarness class final

Gives a widget test a real CoproductClient backed by flag values you set, with no SDK key, no native library, and no network.

The controls live here rather than on the client, so your app code cannot depend on test-only methods.

The harness supplies resolved values. It does not evaluate targeting rules, segments, prerequisites, or rollouts. Set the result your scenario needs, and change it after an identity call if the scenario depends on who is identified.

final harness = CoproductTestHarness()..setBool('new-checkout', false);
addTearDown(harness.shutdown);

await tester.pumpWidget(MaterialApp(
  home: CoproductScope(client: harness.client, child: const CheckoutPage()),
));

harness.setBool('new-checkout', true);
await tester.pumpAndSettle();

Use pumpAndSettle after changing a value, or pump(Duration.zero) if an animation never settles. A bare pump() draws the previous value, because the update arrives just after the frame is scheduled.

When several changes happen before one frame, only the latest value is rendered. Observations report the current value, not every change.

A flag you have not set reads as your default value. The harness starts with client reporting ProviderState.ready

Constructors

CoproductTestHarness({String anonymousId = 'test-anonymous-id'})
Creates a harness with no flags set.

Properties

client → CoproductClient
A real client, accepted anywhere the SDK expects one, such as CoproductScope or CoproductFlagBuilder
no setter
developerAttributes → Map<String, AttributeValue>
The attributes your code set through the identity calls, without the reserved names user_id and targetingKey.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
targetingKey → String
The targeting key the client is using: the anonymous id until an identity call sets a user id or targeting key
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeFlag(String key) → void
Removes the flag, so every read and observation of key returns its own default value. This differs from setJson(key, null), which sets a JSON flag whose value is null. Throws a StateError after shutdown
setBool(String key, bool value) → void
Sets a boolean flag. Observations and builders of key update, and getters return value. Throws a StateError after shutdown
setJson(String key, Object? value) → void
Sets a JSON flag.
setNumber(String key, num value) → void
Sets a number flag, stored as a double.
setProviderState(ProviderState state) → void
Sets what client.state reports, immediately.
setString(String key, String value) → void
Sets a string flag. Observations and builders of key update, and getters return value. Throws a StateError after shutdown
shutdown() → Future<void>
Shuts the harness down, like Coproduct.shutdown for a real client.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited