Improve AdMob adapter test coverage#3204
Merged
Merged
Conversation
Enhance PaidEventTrackingTest with tests that verify TrackingOnPaidEventListener and setUpPaidEventTracking actually call trackAdRevenue with correct AdRevenueData and forward to delegates. Previously, the only test checked that a listener was installed but never verified the tracking or delegation behavior.
Test that onAdShowedFullScreenContent calls trackAdDisplayed and onAdClicked calls trackAdOpened with correct data. Also add negative tests confirming onAdDismissed and onAdFailedToShow do not trigger any tracking calls. Previously only delegation behavior was tested.
Test that onAdLoaded calls trackAdLoaded, onAdImpression calls trackAdDisplayed, onAdClicked calls trackAdOpened, and onAdFailedToLoad calls trackAdFailedToLoad — all with correct data and delegation. Also verify trackAdLoaded=false (used for native ads) skips tracking but still delegates, and negative tests for non-tracking callbacks.
Verify that trackIfConfigured executes its block only when Purchases is configured, skips it when not configured, and passes the correct Purchases instance as the receiver.
Test that an explicit adListener parameter takes precedence over a pre-existing listener on the AdView, and that empty adUnitId is handled gracefully without errors.
Test that interstitial ad load succeeds gracefully when optional params (loadCallback, fullScreenContentCallback, onPaidEventListener, placement) are null. Also verify null loadCallback on failure path does not crash.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3204 +/- ##
=======================================
Coverage 79.32% 79.32%
=======================================
Files 351 351
Lines 14164 14164
Branches 1933 1933
=======================================
Hits 11235 11235
Misses 2126 2126
Partials 803 803 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tonidero
approved these changes
Mar 11, 2026
| } | ||
|
|
||
| companion object { | ||
| private val backingField = Purchases::class.java.getDeclaredField("backingFieldSharedInstance").apply { |
Contributor
There was a problem hiding this comment.
I don't like reflection.... But I guess it's ok for tests and it does simplify a LOT the configuration. So let's keep it as is! 🙏
This was referenced Mar 11, 2026
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Mar 12, 2026
**This is an automatic release.** ## RevenueCat SDK ### ✨ New Features * [EXPERIMENTAL]: Beta Galaxy Store Support (#2903) via Will Taylor (@fire-at-will) ### 🐞 Bugfixes * Skip installation on GCP CLI in run-firebase-test (#3218) via Will Taylor (@fire-at-will) * Fix reduced timeouts being used for HTTP requests when a proxy URL is configured (#3188) via Rick (@rickvdl) ## RevenueCatUI SDK ### 🐞 Bugfixes * Fix missing ripple effect in View-based paywall wrappers (#3206) via Toni Rico (@tonidero) ### Paywallv2 #### ✨ New Features * Rules v0 Integration branch (#3117) via Cesar de la Vega (@vegaro) ### 🔄 Other Changes * [Galaxy]: Add promotionEligibilities comment (#3214) via Will Taylor (@fire-at-will) * [EXTERNAL] Migrate deprecated buildDir to layout API (#3202) contributed by @AlexanderTalledo (#3212) via Toni Rico (@tonidero) * Remove automatic Claude code review workflow (#3211) via Cesar de la Vega (@vegaro) * Remove unused convention plugin (#3195) via Toni Rico (@tonidero) * [EXTERNAL] Integrate convention plugins into Version Catalogs (#3181) contributed by @AlexanderTalledo (#3194) via Toni Rico (@tonidero) * [EXTERNAL] Migrate androidx cardview dependency to version catalogs (#3192) contributed by @AlenxanderTalledo (#3193) via Toni Rico (@tonidero) * Improve AdMob adapter test coverage (#3204) via Pol Miro (@polmiro) * Bump fastlane-plugin-revenuecat_internal from `f5c099b` to `e146447` (#3197) via dependabot[bot] (@dependabot[bot]) * Fix integration tests (#3196) via Toni Rico (@tonidero) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk release bookkeeping: version strings and deployment paths are updated from `9.24.0-SNAPSHOT` to `9.24.0`, plus changelog/docs refresh. Main risk is accidental publishing/docs deployment to the wrong versioned location. > > **Overview** > Cuts the `9.24.0` release by updating all version references from `9.24.0-SNAPSHOT` to `9.24.0` (root `.version`, `gradle.properties`, and `Config.frameworkVersion`), and aligning sample/test app version catalogs to consume the released artifact. > > Updates documentation publishing to point at the `9.24.0` directory (CircleCI S3 sync and `docs/index.html` redirect) and refreshes `CHANGELOG.latest.md`/`CHANGELOG.md` with the `9.24.0` release notes. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8e6d567. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
purchases-iosand hybridsMotivation
The existing AdMob adapter tests verified wiring and delegation but never confirmed that the tracking wrappers actually call the RevenueCat ad tracking APIs (
trackAdRevenue,trackAdDisplayed,trackAdOpened,trackAdLoaded,trackAdFailedToLoad) with correct data. This left critical revenue-path logic untested.Description
Six commits, each addressing one priority tier of identified coverage gaps:
Critical — Paid event revenue tracking: Verify
TrackingOnPaidEventListener.onPaidEventandsetUpPaidEventTrackingcalltrackAdRevenuewith correctAdRevenueDatafields (network name, mediator, format, placement, ad unit, impression ID, revenue micros, currency, precision) and forward to delegates. Also covers null delegate and nullresponseIdedge cases.Critical/High — Full-screen content callback tracking: Verify
TrackingFullScreenContentCallback.onAdShowedFullScreenContentcallstrackAdDisplayedandonAdClickedcallstrackAdOpenedwith correct data. Negative tests confirmonAdDismissedandonAdFailedToShowdo not trigger any tracking.High — Ad listener tracking: Verify
TrackingAdListener.onAdLoaded→trackAdLoaded,onAdImpression→trackAdDisplayed,onAdClicked→trackAdOpened,onAdFailedToLoad→trackAdFailedToLoadwith correct data. Also testtrackAdLoaded=false(used for native ads) skips tracking but still delegates.Medium —
trackIfConfiguredguard: Verify the guard executes its block whenPurchasesis configured, skips when not, and passes the correctPurchasesinstance as the receiver.Medium — Banner listener precedence: Test that an explicit
adListenerparameter takes precedence over a pre-existing listener on theAdView, and that emptyadUnitIdis handled gracefully.Medium/Low — Null optional parameters: Verify interstitial flow doesn't crash when optional params (
loadCallback,fullScreenContentCallback,onPaidEventListener,placement) are null on both success and failure paths.All existing tests continue to pass.
Note
Low Risk
Test-only changes that increase coverage around ad tracking callbacks and listener wiring; no production logic changes, so runtime risk is low.
Overview
Improves AdMob adapter test coverage to assert that the tracking wrappers (
TrackingOnPaidEventListener,TrackingAdListener,TrackingFullScreenContentCallback) invoke the correctAdTrackerAPIs with the expected event payloads (including mediator/network fields, impression IDs, and revenue precision) and still delegate to user-provided callbacks.Adds guard/edge-case tests for
trackIfConfigured, banner listener precedence and emptyadUnitId, and interstitial flows where optional callbacks/params arenull(ensuring no crashes and correct forwarding behavior).Written by Cursor Bugbot for commit 9ee245d. This will update automatically on new commits. Configure here.