Testing local and remote services

When you want to test an android.app.Service, the idea is to extend the ServiceTestCase<Service> class to test in a controlled environment:

public class DummyServiceTest extends ServiceTestCase<DummyService> {
    public DummyServiceTest() {
        super(DummyService.class);
    }

    public void testBasicStartup() {
        Intent startIntent = new Intent();
        startIntent.setClass(getContext(), DummyService.class);
        startService(startIntent);
    }

    public void testBindable() {
        Intent startIntent = new Intent();
        startIntent.setClass(getContext(), DummyService.class);
        bindService(startIntent);
    }
}

The constructor, as in other similar cases, invokes the parent constructor that passes the Android service class as a parameter.

This is followed by testBasicStartup() ...

Get Learning Android Application Testing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.