Android Development

1 minute read

Android Espresso Testing

In part II, we wrote a test case to verify that the app can create a task and the task will be seen on the screen. In this part III, we will demonstrate one technique on writing tests that involves a RecyclerView. First we repeatly add some tasks, and then we verify that the last added task is on display. Note that since we are using a RecyclerView, the last item might not be seen, so we need to scroll the RecyclerView before checking.

1 minute read

Android Espresso Testing

In Part I we talked about how to setup Espresso testing framework, what is the activity testing rule and how to use uiautomatorviewer to help us find id of the view quickly. In this Part II, we will write some tests against a simple TODO list application. Lets get started. About the App under test This is a very simple app with basically 2 screens. One to display a list of tasks:

5 minute read

Android Espresso Testing

The Espresso testing framework really makes it easy to write UI tests for Android. In this first installment, I will go through how to set it up and write our first test case. Let’s get started. Set up Espresso Add the following dependencies to your gradle build file. dependencies { // Other dependencies … androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' } Understand the Rules in JUnit Why do they exist? We all know that in JUnit there is a setup method(annotated as @Before) and a teardown method(annotated as @After).

1 minute read

I don’t remember since when, but now whenever I upgrade Android Studio from pacman, I cannot open my emulator, with some libGL error: unable to load driver: i965_dri.so error. I tried to follow the solution online but found none of them is working out of the box, because Android Sdk changed some paths. Here is what actualy works now: cd ANDROID_SDK_PATH/emulator/lib64/libstdc++/ mv libstdc++.so.6 libstdc++.so.6.bak ln -s /usr/lib64/libstdc++.so.6 libstdc++.so.6

2 minute read

RxJava Android

In this post we talk about how to use Observable.fromCallable() and Observable.defer() to convert exising functionality into the Rx. Imagine that you have a UserService class, in it there is a getUserFromDb() function. This function is developed before RxJava and cannot be changed. But somehow you need a function which returns a Observable<User>. What could you do? The UserService Example public class UserService { /** * Gets User from database, this should not be run in UI thread.