无法从测试类截获android状态栏通知

无法从测试类截获android状态栏通知,android,unit-testing,service,notifications,Android,Unit Testing,Service,Notifications,我有一个扩展了ServiceTestCase的测试类,它具有以下方法: public void testNotificationIntercepted() throws Exception { bindService(new Intent(getContext(), NotificationInterceptor.class)); // Our service is already started. Create and send a notification. N

我有一个扩展了
ServiceTestCase
的测试类,它具有以下方法:

  public void testNotificationIntercepted() throws Exception {
    bindService(new Intent(getContext(), NotificationInterceptor.class));

    // Our service is already started. Create and send a notification.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext());
    builder.setContentTitle("Hello World");
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setContentText("What's up?");
    Notification notif = builder.build();
    NotificationManager mgr =
        (NotificationManager)getContext().getSystemService(Context.NOTIFICATION_SERVICE);
    mgr.notify(1492, notif);

    // Now, get our service and make sure that the notification was intercepted.
    final NotificationInterceptor iceptor = getService();

    List<NotificationBundle> notifications = iceptor.getNotificationsSeen();

    assertEquals(1, notifications.size());

    mgr.cancel(1492);
  }
public void testNotificationIntercepted()引发异常{
bindService(新意图(getContext(),NotificationInterceptor.class));
//我们的服务已启动。请创建并发送通知。
NotificationCompat.Builder=新建NotificationCompat.Builder(getContext());
builder.setContentTitle(“Hello World”);
builder.setSmallIcon(R.drawable.ic_启动器);
setContentText(“怎么了?”);
通知notif=builder.build();
通知经理=
(NotificationManager)getContext().getSystemService(Context.NOTIFICATION_服务);
经理通知(1492,notif);
//现在,获取我们的服务并确保通知被拦截。
最终通知拦截器iceptor=getService();
列表通知=iceptor.getNotificationsSeen();
assertEquals(1,notifications.size());
经理取消(1492);
}
NotificationInterceptor
类有一个方法,
onNotificationPosted()
,它本质上只是在通知发布到设备时将其添加到列表中(为了我的目的将其解析为更易于使用的格式之后)。问题是这个方法永远不会被调用

我怀疑测试应用程序没有适当的权限,因为它不是一个单独的项目(我使用的是AndroidStudio),因此没有自己的AndroidManifest.xml文件。应用程序本身在AndroidManifest.xml文件和设置菜单的安全->通知部分都有权限

有没有一种方法可以用来测试我的服务的功能?(在实际应用程序的上下文中,它似乎工作正常……我只想编写一个测试,以确保它不会中断,因为我将来可能会重构一些东西)