fix(ads): force test ad units in release during closed testing

Closed-testing human testers cannot be registered as AdMob test
devices, so release builds serving real ad units risked invalid
traffic against an AdMob account that currently earns essentially
nothing. Add usarAnunciosDePruebaEnRelease, a single boolean switch
defaulted to true, that keeps bannerAdUnitId/interstitialAdUnitId on
Google's official test ids even in kReleaseMode. Flipping it to false
is the only change needed to go live. AndroidManifest's AdMob
application id is untouched, as it only initializes the SDK.
This commit is contained in:
2026-08-28 19:49:12 +02:00
parent e9f47d47c2
commit 2e15d05431
2 changed files with 50 additions and 5 deletions
+20 -5
View File
@@ -15,13 +15,28 @@ const _bannerAdUnitIdReal = 'ca-app-pub-6038935671414339/5658618378';
/// Real interstitial unit id, provisioned in the AdMob console (iap-freemium-unlock).
const _interstitialAdUnitIdReal = 'ca-app-pub-6038935671414339/4189478248';
/// Real id in release builds only; test id everywhere else (debug/profile,
/// including internal-testing-track builds run via `flutter run --release`
/// on a personal device — see the "never tap your own ads" note above).
/// TESTING-PHASE SWITCH. While `true`, release builds serve Google's official
/// TEST ad units instead of the real ones, so none of the closed-testing
/// human testers can generate invalid traffic against the AdMob account
/// (they cannot be registered as AdMob test devices). Flip to `false` for
/// the production release — that is the ONLY change needed to start serving
/// real ads. This does NOT affect the AdMob application id in
/// `AndroidManifest.xml`, which stays real in every build (it only
/// initializes the SDK and carries none of the click risk).
const usarAnunciosDePruebaEnRelease = true;
/// Real id in release builds only, and only once [usarAnunciosDePruebaEnRelease]
/// is flipped to `false`; test id everywhere else (debug/profile, including
/// internal-testing-track builds run via `flutter run --release` on a
/// personal device — see the "never tap your own ads" note above).
const bannerAdUnitId =
kReleaseMode ? _bannerAdUnitIdReal : bannerAdUnitIdPrueba;
kReleaseMode && !usarAnunciosDePruebaEnRelease
? _bannerAdUnitIdReal
: bannerAdUnitIdPrueba;
const interstitialAdUnitId =
kReleaseMode ? _interstitialAdUnitIdReal : interstitialAdUnitIdPrueba;
kReleaseMode && !usarAnunciosDePruebaEnRelease
? _interstitialAdUnitIdReal
: interstitialAdUnitIdPrueba;
/// Ads port + AdMob adapter (Design "Interfaces / Contracts", ADR-6): owns
/// the entitlement gate for both surfaces, the interstitial's session
@@ -161,6 +161,36 @@ void main() {
});
});
group('usarAnunciosDePruebaEnRelease — interruptor de fase de pruebas', () {
test('mientras esta en true, bannerAdUnitId e interstitialAdUnitId son los '
'ids oficiales de prueba de Google', () {
expect(usarAnunciosDePruebaEnRelease, isTrue);
expect(bannerAdUnitId, equals('ca-app-pub-3940256099942544/6300978111'));
expect(
interstitialAdUnitId,
equals('ca-app-pub-3940256099942544/1033173712'),
);
});
test('los ids reales siguen presentes como constantes en el archivo (no se '
'pueden perder en un futuro edit)', () {
final source =
File('lib/servicios/servicio_anuncios.dart').readAsStringSync();
expect(
source.contains("'ca-app-pub-6038935671414339/5658618378'"),
isTrue,
reason: 'el id real del banner debe seguir presente en el archivo',
);
expect(
source.contains("'ca-app-pub-6038935671414339/4189478248'"),
isTrue,
reason:
'el id real del interstitial debe seguir presente en el '
'archivo',
);
});
});
group('debeMostrarBanner', () {
test('free: true', () {
final servicio = construir(