FakeAdManager class

A fake AdManager for testing.

Allows tests to control ad behavior without real ad SDK calls. All methods are synchronous and predictable.

// In your test:
final fakeManager = FakeAdManager();

// Control interstitial behavior
fakeManager.nextInterstitialResult = true;

// Control rewarded behavior
fakeManager.nextRewardedResult = const AdReward(
  amount: 50,
  type: 'coins',
);

// Inject into widget under test
await tester.pumpWidget(
  BannerAdWidget(manager: fakeManager),
);

// Emit a custom event to verify listener behavior
fakeManager.emitEvent(const AdEvent(type: AdEventType.shown));
Implemented types

Constructors

FakeAdManager({AdConfig? config})
Creates a fake ad manager with optional config.

Properties

config AdConfig
The configuration used by this manager.
no setteroverride
Access to the UMP consent manager.
no setteroverride
disableAppOpenAdCallCount int
The number of times disableAppOpenAd has been called.
getter/setter pair
disposeCallCount int
The number of times dispose has been called.
getter/setter pair
enableAppOpenAdCallCount int
The number of times enableAppOpenAd has been called.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
initializeCallCount int
The number of times initialize has been called.
getter/setter pair
interstitialState AdState
The current state of the interstitial ad.
no setteroverride
isDisposed bool
Whether the manager has been disposed.
no setter
isInitialized bool
Whether initialize has been called successfully.
no setteroverride
loadInterstitialCallCount int
The number of times loadInterstitial has been called.
getter/setter pair
loadRewardedCallCount int
The number of times loadRewarded has been called.
getter/setter pair
nextInterstitialResult bool
Controls the return value of showInterstitial.
getter/setter pair
nextRewardedResult AdReward?
Controls the return value of showRewarded.
getter/setter pair
onAdEvent Stream<AdEvent>
A broadcast stream of all ad events.
no setteroverride
rewardedState AdState
The current state of the rewarded ad.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showInterstitialCallCount int
The number of times showInterstitial has been called.
getter/setter pair
showRewardedCallCount int
The number of times showRewarded has been called.
getter/setter pair
simulateLoadFailure bool
Controls whether loadInterstitial should simulate failure.
getter/setter pair
simulateRewardedLoadFailure bool
Controls whether loadRewarded should simulate failure.
getter/setter pair

Methods

addListener(void listener(AdEvent event)) → void
Registers an event listener callback.
override
disableAppOpenAd() → void
Disables app-open ads and unregisters the lifecycle observer.
override
dispose() → void
Releases all ad resources and cancels subscriptions.
override
emitEvent(AdEvent event) → void
Emits an event to both the stream and registered listeners.
override
enableAppOpenAd() → void
Enables app-open ads.
override
initialize() Future<void>
Initializes AdMob SDK and runs the UMP consent flow.
override
loadInterstitial() Future<void>
Preloads an interstitial ad.
override
loadRewarded() Future<void>
Preloads a rewarded ad.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeListener(void listener(AdEvent event)) → void
Removes a previously registered event listener.
override
showInterstitial() Future<bool>
Shows a preloaded interstitial ad.
override
showRewarded() Future<AdReward?>
Shows a preloaded rewarded ad and returns the reward.
override
toString() String
A string representation of this object.
inherited

Operators

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