How to test remote Android support service

I have a small application that interacts with a remote android service. I would like to mock this service in unit tests. I use Robolectric and JUnit for other test cases and shadows, but I could not figure out how to handle remote services.

Is it enough to create and run a test service using the same package with real services and export methods using the same aidl ?

Since I do not have code for this service, I assume that I cannot use Robolectric ShadowService , which requires an actual class.

Thank you very much.

+45
java android robolectric
Jun 09 '12 at 12:14
source share
1 answer

I would use Mockito to create a Mock interface, and then pass this instance to your code in your tests. You can also manually create an implementation of this interface in your test code and use it.

So, you need to make a mockery of yourself, and it is important that the code you want to test use some form of dependency injection in order to get a link to the aidl interface so that you can pass your own layout in your tests.

+1
Dec 29 '15 at 7:57
source share



All Articles