Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I test status bar notifications using Android's testing framework?

I have a class that sends a status bar notification in Android. I can't find a way to test whether the notification was sent or not, which makes it very hard to write any kind of useful unit test.

Does anyone have a solution for this?

like image 316
defrex Avatar asked Oct 28 '10 17:10

defrex


People also ask

How do you test notifications?

Sending a test Android push notificationClick on Settings and open Mobile Apps. Click on the Android App and make sure the Firebase API key has been configured. Click on Test Push and enter the device token for your test device. Add a test payload and send the test.

What is a status bar notification?

Status bar (or notification bar) is an interface element at the top of the screen on Android devices that displays the notification icons, minimized notifications, battery information, device time, and other system status details.

What is an Android testing framework?

Android App Development for Beginners The Android framework includes an integrated testing framework that helps you test all aspects of your application and the SDK tools include tools for setting up and running test applications.

What is Android studio used for in testing?

If you want to learn more about the fundamentals of testing and how to write tests, see Test apps on Android. There are different ways to run and configure your tests: For basic testing needs, Android Studio includes features that help you create, run, and view results of tests all from the IDE.


1 Answers

Maybe not the answer you are looking for, but as usual the solution is to:

  • Create an interface abstracting the notification functionality.
  • Create a default implementation that delegates to the system notification API.
  • When running tests replace (or decorate) the default implementation with a mock implementation that supports testing.

This can be simplified with the following technology:

  • Dependency injection frameworks (such as RoboGuice) to streamline the choice of implementation.
  • Mocking library (such as EasyMock) to automate creation of mock implementations.
like image 187
Michael Smith Avatar answered Oct 05 '22 15:10

Michael Smith