My Android app includes a service that sends notifications based on various triggers, like the number of times the app is run.
Since notifications can be sent at different times depending on the scenario, I’m looking for reliable methods for testing notifications to ensure they’re delivered at the right moments.
Does Android provide native tools or recommended practices for accurately testing notifications across multiple use cases?
I’ve found that using Espresso + NotificationManager helps test whether the notification was actually posted.
I use NotificationManager.getActiveNotifications() in my instrumentation tests to verify if the expected notification is present with the correct title and content.
It’s not perfect for timing-based logic, so I also include log checks to verify that triggers fire as expected under different conditions.
For our team, we simulate different device states (like background, Doze mode, or locked screen) using tools like Firebase Test Lab and ADB shell commands.
These let us check how notifications behave under different battery-saving modes or network restrictions.
We also create mock triggers in dev builds to force specific notification paths without needing to hit real backend events every time.
In my experience, building test hooks or debug flags into the app helps a lot.
For example, I expose a debug menu in dev builds that lets me manually fire the same events that would normally trigger a notification (like app open count or background services).
This way, I can run manual or automated tests to verify notification delivery and content across edge cases without needing the actual user behavior to occur.