-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add Robolectric tests for NativeAdLoader #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codex Review: Here are some suggestions.
Reply with @codex fix comments
to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
@Test | ||
public void loadSuccessAddsPopulatedViewAndRequestsLayout() { | ||
Context context = ApplicationProvider.getApplicationContext(); | ||
TestContainer container = new TestContainer(context); | ||
AdRequest adRequest = mock(AdRequest.class); | ||
|
||
NativeAd nativeAd = mock(NativeAd.class); | ||
when(nativeAd.getHeadline()).thenReturn("Headline"); | ||
when(nativeAd.getBody()).thenReturn("Body"); | ||
when(nativeAd.getCallToAction()).thenReturn("Install"); | ||
when(nativeAd.getAdvertiser()).thenReturn("Advertiser"); | ||
|
||
AtomicReference<NativeAd.OnNativeAdLoadedListener> listenerRef = new AtomicReference<>(); | ||
|
||
try (MockedConstruction<AdLoader.Builder> mocked = mockConstruction(AdLoader.Builder.class, (builder, ctx) -> { | ||
when(builder.forNativeAd(any())).thenAnswer(inv -> { | ||
listenerRef.set(inv.getArgument(0)); | ||
return builder; | ||
}); | ||
when(builder.withAdListener(any())).thenReturn(builder); | ||
AdLoader adLoader = mock(AdLoader.class); | ||
when(builder.build()).thenReturn(adLoader); | ||
doAnswer(inv -> { | ||
listenerRef.get().onNativeAdLoaded(nativeAd); | ||
return null; | ||
}).when(adLoader).loadAd(any(AdRequest.class)); | ||
})) { | ||
NativeAdLoader.load(context, container, R.layout.ad_home_banner_large, adRequest, null); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Enable Android resources for Robolectric tests
The new Robolectric tests call NativeAdLoader.load
with R.layout.ad_home_banner_large
(lines 37‑65) which inflates a real layout. Unit tests in this module currently run without packaged Android resources because android { testOptions.unitTests.includeAndroidResources = true }
is not configured in app/build.gradle
. With the default setting, Robolectric will throw Resources$NotFoundException
when inflating the layout and the tests will never reach their assertions. Please turn on includeAndroidResources
or move the tests to androidTest
so resources are available.
Useful? React with 👍 / 👎.
Summary
Testing
./gradlew test
(fails: SDK location not found)https://chatgpt.com/codex/tasks/task_e_68c67a737410832d99201c3820bc052b