mercredi 1 août 2018

How to set up an instrumented unit test for an accessibility serivce

I have such test code:

class MyAccessibilityServiceTest {

  @get:Rule
  val mServiceRule = ServiceTestRule()


  @Test
  fun test() {
    val serviceIntent = Intent(
        InstrumentationRegistry.getTargetContext(),
        MyAccessibilityService::class.java
    )

    val binder: IBinder = mServiceRule.bindService(serviceIntent)

    // Service is not initialized at this point.
    // The system has not called its onServiceConnected()
  }
}

When I start to interact with the binder, it turns out that the service is not initialized. Its AccessibilityService.onServiceConnected() is not called. I confirmed that with debugger.

How should I bind to the service so that the system calls onServiceConnected()?

Aucun commentaire:

Enregistrer un commentaire