¿Cómo probar mi objeto IBinder
que Service
devuelve onBind
?Android Service Testing
Respuesta
De acuerdo con la interfaz remota que utiliza entre su contexto y el servicio (en el escenario de llamada remota). Por ejemplo, usted puede hacer así:
IBinder service = this.bindService(new Intent(TestService.class.getName()));
assertNotNull(service);
assertTrue(service instanceof ITestServiceCall); //see if the service returns the correct interface
ITestServiceCall iTestServiceCall = ITestServiceCall.Stub.asInterface(service);
assertNotNull(iTestServiceCall);
iTestServiceCall.doSomething();
El ITestServiceCall es la interfaz que se define en un archivo AIDL (ITestServiceCall.aidl).
Pero antes de que esto pueda funcionar, debe asegurarse de que su servicio devuelva el Stub de su interfaz correctamente en onBind().
Espero que esto pueda ayudar.
es una mala idea probar su carpeta inmediatamente después de haber llamado bindService. Este método es asíncrono y no devuelve nada interesante antes de que se llame a ServiceConnection onServiceConnected – Snicolas
No hay 'ServiceConnection.onServiceConnected()' utilizado en ServiceTestCase, es por eso que obtenemos el objeto IBinder inmediatamente después de 'bindService()'. Esto es diferente del flujo de servicio real, creo. –
- 1. Testing GPS en Android
- 2. Android Unit Testing: Paquete/Parcelable
- 3. Android Testing - Problema con ActivityInstrumentationTestCase2?
- 4. BDD Android UI testing framework?
- 5. Live Testing de Android LVL
- 6. Android: AsyncTask vs Service
- 7. Android Web Service Tutorial
- 8. Android NFC start service
- 9. Android service parámetro startId
- 10. android service startService() and bindService()
- 11. Mocking up WifiManager for Android Unit Testing
- 12. UI testing vs unit testing
- 13. Cómo consumir WCF Service con Android
- 14. Service call backs to activity in android
- 15. android services - error: service not registered
- 16. Android: ¿Cuándo usar Service vs Singleton?
- 17. SyncML con Android y PHP Web Service
- 18. Testing helpers
- 19. WCF Service vs Windows Service
- 20. ¿Cómo usar Mockito con dexmaker para Android Testing?
- 21. SOAP Web Service/VS2010 Add Service Reference
- 22. Grails withCriteria testing
- 23. Live testing jQuery selector
- 24. New to Unit Testing
- 25. Javascript Sandbox unit testing
- 26. Monkey testing for iPhone?
- 27. unit testing modular javascript
- 28. JUnit Exception Testing
- 29. spring junit testing
- 30. Integration Testing the Canvas
¡Acepte la respuesta han pasado más de 3 años! – JPM