Skip to content

Improve AdMob adapter test coverage#3204

Merged
polmiro merged 6 commits into
mainfrom
admob-test-coverage
Mar 11, 2026
Merged

Improve AdMob adapter test coverage#3204
polmiro merged 6 commits into
mainfrom
admob-test-coverage

Conversation

@polmiro

@polmiro polmiro commented Mar 10, 2026

Copy link
Copy Markdown
Member

Checklist

  • If applicable, unit tests
  • If applicable, create follow-up issues for purchases-ios and hybrids

Motivation

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:

  1. Critical — Paid event revenue tracking: Verify TrackingOnPaidEventListener.onPaidEvent and setUpPaidEventTracking call trackAdRevenue with correct AdRevenueData fields (network name, mediator, format, placement, ad unit, impression ID, revenue micros, currency, precision) and forward to delegates. Also covers null delegate and null responseId edge cases.

  2. Critical/High — Full-screen content callback tracking: Verify TrackingFullScreenContentCallback.onAdShowedFullScreenContent calls trackAdDisplayed and onAdClicked calls trackAdOpened with correct data. Negative tests confirm onAdDismissed and onAdFailedToShow do not trigger any tracking.

  3. High — Ad listener tracking: Verify TrackingAdListener.onAdLoadedtrackAdLoaded, onAdImpressiontrackAdDisplayed, onAdClickedtrackAdOpened, onAdFailedToLoadtrackAdFailedToLoad with correct data. Also test trackAdLoaded=false (used for native ads) skips tracking but still delegates.

  4. Medium — trackIfConfigured guard: Verify the guard executes its block when Purchases is configured, skips when not, and passes the correct Purchases instance as the receiver.

  5. Medium — Banner listener precedence: Test that an explicit adListener parameter takes precedence over a pre-existing listener on the AdView, and that empty adUnitId is handled gracefully.

  6. 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 correct AdTracker APIs 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 empty adUnitId, and interstitial flows where optional callbacks/params are null (ensuring no crashes and correct forwarding behavior).

Written by Cursor Bugbot for commit 9ee245d. This will update automatically on new commits. Configure here.

polmiro added 6 commits March 10, 2026 14:20
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

codecov Bot commented Mar 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.32%. Comparing base (5f639a1) to head (9ee245d).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@polmiro polmiro requested a review from tonidero March 11, 2026 08:40
@polmiro polmiro marked this pull request as ready for review March 11, 2026 08:40
@polmiro polmiro requested a review from a team as a code owner March 11, 2026 08:40
@polmiro polmiro enabled auto-merge March 11, 2026 08:40

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moar tests! 🫶

}

companion object {
private val backingField = Purchases::class.java.getDeclaredField("backingFieldSharedInstance").apply {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! 🙏

@polmiro polmiro added this pull request to the merge queue Mar 11, 2026
Merged via the queue into main with commit 2463e75 Mar 11, 2026
32 checks passed
@polmiro polmiro deleted the admob-test-coverage branch March 11, 2026 09:24
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants