Skip to main content

Posts

Showing posts from October, 2016

Android : Sharing code and resources between UI and unit tests

As an Android developer you are already familiar with writing Unit and UI tests. This post is about "How to share the code and resources between your UI and unit tests?". I'd used "Appointments List" as an example scenario for this post. Existing Setup For UI testing, I'd have list of appointments API response in JSON format as "appointments.json" in res directory. The .json file is is converted to AppointmentsListResponse using JsonParser. androidTest/java/com/example/AppointmentScreenTest.java AppointmentsListResponse getFakeAppointmentsResponse() { InputStream in = getInstrumentation ().getContext() .getResources() .openRawResource(com.example.android.internal.test.R.raw.appointments); AppointmentsListResponse fakeResponse = new JsonParser(in).parseTo(AppointmentsListResponse. class ); } androidTest/ java/ com/example/JsonParser.java public class JsonParser String mStringToParse; private static Gson mGso