mercredi 18 avril 2018

Combine Android instrumentation tests and backend integration tests

I manage unit tests and integration tests for a complex Spring-based backend project. The tests should be extended by end-to-end test which check the interaction between the backend and Android clients.

A simple test case whould be "When an event is triggered on the backend server, there should be a notification shown on the device".

The first thing I tried was implementing Android instrumentation tests but hit a wall when it comes to the backend interaction. Tests include calls to many different services and remote database operations and I feel this heavy liftig should not happen on the Android device. Another issue is that making the current Spring test environment work in an Android environment is a huge PITA.

The second thing I tried was integrating calls to Android's build tool gradle into my test logic. This means I executed a command line call like ./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=MyTestClass#notificationCheck and checked the call for a positive execution result. This produced somewhat correct test results but felt very sluggish because of the rather long execution times of the command line calls.

I use the Android UI Automator library for cross-application testing. Mocking calls to and from the backend on the Android device is not an option.

How can I include Android instrumentation checks in my plain integration tests? What are technical solutions for this? Do solutions for such a scenario already exist?

A sample test could look like this:

class NotificationEventTest{
    @Autowired
    private MyService service;

    private AndroidDevice device = AndroidDevice.getConnectedDevice();

    @Test
    public void notificationEventTest(){
        service.createEvent();
        device.checkNotification();
    }
}

Aucun commentaire:

Enregistrer un commentaire