Android UI Testing using Kakao DSL

Android UI Testing using Kakao DSL

UI Testing Basic Introduction

UI Testing Importance

UI testing is a common practice to ensure that the application meets the expected behaviour along with providing high standard quality to the end-users.

Usually, human testers test the possible job flows in the target app to assure the working behaviour and quality of the application. But this could be time-taking, tiring and error-prone.

Therefore the more efficient way for testing the app is to write UI tests for all possible flows of the app so that the user required actions are performed in an automated way. These tests can be executed efficiently and in a repeatable manner to utilise time and ensure the expected behaviour and quality of the app.

UI Testing Frameworks

Espresso

Android provides default support of Espresso for writing UI tests. Espresso is quite powerful and easy to learn testing UI framework for the developers. UI tests in Espresso look something like this.

@Test
fun greeterSaysHello() {
    onView(
        allOf(withId(R.id.price_item), 
        hasDescendant(withText("Standard Rate")))
    ).check(matches(withEffectiveVisibility(Visibility.VISIBLE)));
}

Does it look easy to read? actually, Espresso generates more boilerplate code which becomes hard to understand and manageable for the developers. Please check some more samples of Espresso UI tests here

Kakao

Kakao is nice and simple DSL for Espresso written in Kotlin. Writing UI tests using Kakao improves the code readability. UI tests in Kakao look like this.

@Test
fun insertNewTaskHappyPath() {
    onScreen<HomeScreen> {
        performClickOnFAButton()
    }
    onScreen<NewTaskScreen> {
        saveHappyTask()
    }
    onScreen<HomeScreen> {
        assertRecyclerView()
    }
}

It looks more pretty and easy to understand the tests written in Kakao.

Android Test Package

It is strongly recommended to use Android Studio for writing Android UI tests because it provides project setup, libraries inclusion, and separate package src/androidTest/java for writing the tests. Android Plug-in for Gradle makes our UI tests runnable and launches the instrumentation runner to simulate user actions by running those UI tests.

System Animations

Before writing tests, it is recommended to disable your system animations from device settings → developer options

  • Window animation scale
  • Transition animation scale
  • Animator duration scale

Leaving system animations turned on in the test device might cause unexpected results or may lead your test to fail.

SO,

In the upcoming parts of UI testing, we’ll be using Kakao DSL. meme.png

What Next?

1 — Write First UI Test in Android Article
I will be posting more articles on UI testing, stay tuned.