Skip to content

04. Robot pattern

Bajic Dusko edited this page Oct 29, 2018 · 1 revision

AndroidTest KTX is meant to be used with Robot pattern in mind. However, it's not a mandatory approach.

What the heck is Robot pattern? Google it :)

  • Shortly, each screen has its robot.
  • Each robot has its own collections of functions.
  • Robot functions are the ones using the DSL we're writing.

In order to increase the readability of the Robot, some DSL functions might be named "strangely":

Example

Checking whether the UIObject is displayed or not.

/**
 * Asserts whether the UIObject is displayed.
 */
fun UiObject.itIsDisplayed() {
  assertTrue(exists())
}

The function is called, itIsDisplayed. You're wondering, why not isDisplayed?

When used in the robot, you'll probably have some function called loginButtonIsDisplayed(). Inside of this function, the component visibility is inspected and it'll probably look like this:

fun loginButtonIsDisplayed(){
  val loginButton = viewById(R.id.loginButton)
  loginButton verifyThat { itIsDisplayed() }
}

When you read it, it makes more sense than:

  loginButton verifyThat { isDisplayed() }

It's a small thing, however, having a bunch of these functions tends to be overwhelming and the time spent understanding these functions has to be decreased as much as possible. Readability helps a lot, and if we manage to have these expressions human-like, readable and understandable. Someone in the future will be very grateful.

Clone this wiki locally