Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6546731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:44:38+00:00 2026-05-25T11:44:38+00:00

In order to use test-driven development principles for code involving the Android status bar,

  • 0

In order to use test-driven development principles for code involving the Android status bar, I would need to write tests that verify an expected state has been achieved. For example, a little unit test like the following would allow me to verify that the notification I intended to put up is actually showing:

public class NotificationTest extends AndroidTestCase {

  public void testCanNotify() {
    // setup SUT
    NotificationManager mgr = (NotificationManager) getContext().getSystemService(
            Context.NOTIFICATION_SERVICE);
    Notification notif = new Notification(android.R.drawable.stat_notify_error, "ticker", 0);
    PendingIntent intent = PendingIntent.getActivity(getContext(), 0, null, 0);
    notif.setLatestEventInfo(getContext().getApplicationContext(), "title", "text", intent);
    int id = 123;

    // exercise SUT
    mgr.notify(id, notif);

    // verify result
    // QUESTION: HERE I WOULD LIKE TO SAY:
    // assertTrue(mgr.isShowing(id));

    // teardown
    mgr.cancel(id);
  }
}

So as the example shows, the notification manager itself does not seem to have any diagnostic methods such as isShowing(id) or get(id) which I could use for the “verify” step in the test.

I have looked at the excellent Robotium toolkit, but they are very specific about testing a single application, so they don’t cover notifications.

Does anyone know a solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:44:39+00:00Added an answer on May 25, 2026 at 11:44 am

    I wouldn’t normally test whether a third party or system api works as expected. I would use a mock NotificationManager and verify whether my production code calls notify with the correct parameters. Whether the real NotificationManager behaves properly isn’t really something you control.

    If NotificationManager is resistant to mocking you can try wrapping it in a thin class that’s under your control.

    The only time I test a third party or system api is when it is poorly documented and I need to confirm a guess about its behavior. These kind of tests are usually thrown away once I have my answer. If this is the case and you are finding it difficult to test using a test framework you can always create a simple application and visually verify the results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to test driven development and first time I'm tring to use it
I do test driven development of c++ code and one thing I find awkward
I am trying to use test-driven development for an application that has to read
I'm trying to use fixtures to add more complex test data in order to
In order to use normal mapping in GLSL shaders, you need to know the
I've found that in order to use PRISM's classes in XAML you need to
I'm having trouble discovering exactly what I need to implement in order to use
I'm trying to use the @Test(expected = RuntimeException.class) annotation in order to test for
I'm getting started with Boost::Test driven development (in C++), and I'm retrofitting one of
I'm trying to use the DataAnnotationsModelBinder in order to use data annotations for server-side

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.