Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Test Robots

Test Robots

Daniel

June 05, 2019
Tweet

More Decks by Daniel

Other Decks in Technology

Transcript

  1. (Kotlin + patterns) * ui-tests = happy developer Daniel Gomez

    Rico
 @aquicaipivara Android Lead Developer at Barista Ventures
  2. @Test fun test_login_showMainView() { // write email // write password

    // click login button // check if user logged in successfully } Test login works
  3. @Test
 fun test_login_showMainView() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"),

    ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } Login test on
  4. @Test
 fun test_login_showMainView() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"),

    ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } Login test on
  5. @Test
 fun test_login_showMainView() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"),

    ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } Login test on
  6. @Test
 fun test_login_showMainView() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"),

    ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } Login test on
  7. @Test
 fun test_login_showMainView() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"),

    ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } est
 test_login_doThis() {
 presso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 presso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 presso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 presso.onView(ViewMatchers.withText(“Main"))
 check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 st
 est_login_withSomething() {
 resso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 erform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 resso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 erform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 resso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 erform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 resso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 erform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 resso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 resso.onView(ViewMatchers.withText(“Main"))
 heck(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 @Test
 fun test_login_doOther() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } @Test
 fun test_login_doMore() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click( 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 @Test
 fun test_login_doOther() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeybo 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeybo 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewAction 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } @Test
 fun test_login_doOther() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } @Test
 fun test_login_doOther() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } @Test
 fun test_login_doOther() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } oOther() {
 ew(ViewMatchers.withId(R.id.loginUsernameEditText))
 wActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 ew(ViewMatchers.withId(R.id.loginPasswordEditText))
 wActions.typeText("007"), ViewActions.closeSoftKeyboard())
 ew(ViewMatchers.withId(R.id.loginUsernameEditText))
 wActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 ew(ViewMatchers.withId(R.id.loginPasswordEditText))
 wActions.typeText("007"), ViewActions.closeSoftKeyboard())
 ew(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 ew(ViewMatchers.withText(“Main"))
 Assertions.matches(ViewMatchers.isDisplayed()))
 @Test
 fun test_login_doOther() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click())
 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 } @Test
 fun test_login_doOther() {
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText))
 .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard 
 Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))
 .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard())
 
 Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.c 
 Espresso.onView(ViewMatchers.withText(“Main"))
 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
 }
  8. @Test fun test_login_showMainView() { // write email // write password

    // click login button // check if user logged in successfully } Login test
  9. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))

    .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard()) Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click()) Espresso.onView(AllOf.allOf(ViewMatchers.withText("Main"))) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) }
  10. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail(“[email protected]") Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText))

    .perform(ViewActions.typeText("007"), ViewActions.closeSoftKeyboard()) Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click()) Espresso.onView(AllOf.allOf(ViewMatchers.withText("Main"))) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) }
  11. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") loginRobot.writePassword("007")

    Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(click()) Espresso.onView(AllOf.allOf(ViewMatchers.withText("Main"))) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) }
  12. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") loginRobot.writePassword("007")

    Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click()) Espresso.onView(AllOf.allOf(ViewMatchers.withText("Main"))) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) }
  13. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") loginRobot.writePassword("[email protected]")

    val mainRobot = loginRobot.clickLoginButton() // Returns a MainRobot Espresso.onView(AllOf.allOf(ViewMatchers.withText("Main"))) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) }
  14. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") loginRobot.writePassword("[email protected]")

    val mainRobot = loginRobot.clickLoginButton() // Returns a MainRobot Espresso.onView(AllOf.allOf(ViewMatchers.withText("Main"))) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) }
  15. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") loginRobot.writePassword("[email protected]")

    val mainRobot = loginRobot.clickLoginButton() // Returns a MainRobot Espresso.onView(AllOf.allOf(ViewMatchers.withText("Main"))) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) }
  16. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") loginRobot.writePassword("[email protected]")

    val mainRobot = loginRobot.clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } @Test fun test_login_showMainView() { Espresso.onView(ViewMatchers.withId(R.id.loginUsernameEditText)) .perform(ViewActions.typeText("[email protected]"), ViewActions.closeSoftKeyboard()) Espresso.onView(ViewMatchers.withId(R.id.loginPasswordEditText)) .perform(ViewActions.typeText(“007”), ViewActions.closeSoftKeyboard()) Espresso.onView(ViewMatchers.withId(R.id.loginSubmitButton)).perform(ViewActions.click()) Espresso.onView(AllOf.allOf(ViewMatchers.withText("Main"))) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) }
  17. class LoginRobot { fun writeEmail(text: String) { onView(withId(R.id.loginUsernameEditText)).perform(typeText(text), closeSoftKeyboard()) }

    fun writePassword(text: String) { onView(withId(R.id.loginUsernameEditText)).perform(typeText(text), closeSoftKeyboard()) } fun clickLoginButton(): MainRobot { onView(withId(R.id.loginSubmitButton)).perform(ViewActions.click()) return MainRobot() } } class MainRobot { fun checkIsVisible() { onView(allOf(instanceOf(TextView::class.java), withParent(withId(R.id.toolbar)))) .check(matches(withText(“Main”))); } } The robots
  18. open class BaseRobot { fun click(id: Int) { onView(withId(id)).perform(ViewActions.click()) }

    } class LoginRobot : BaseRobot() { fun clickLogin() { click(R.id.loginButton) } }
  19. open class BaseRobot { fun click(id: Int) { takeScreenshot("before_click") onView(withId(id)).perform(ViewActions.click())

    takeScreenshot(“after_click”) } fun takeScreenshot(screenName: String) { //... } } class LoginRobot : BaseRobot() { fun clickLogin() { click(R.id.loginButton) } }
  20. class MapApi { constructor(host: String) {} constructor(host: String, port: Int,

    listener: Listener?) {} } class Order { val mapApi = MapApi(“http://droids4droids.com/places", 23, null) } class Order { val mapApi = MapApi(“http://droids4droids.com/places", 23, this) }
  21. class MapApi { object Builder { fun withHost(host: String): Builder

    { return this } fun withPort(port: Int): Builder { return this } fun withListener(listener: Listener): Builder { return this } fun build() : MapApi { return MapApi(…) } } }
  22. class MapApi { object Builder { fun withHost(host: String): Builder

    { return this } fun withPort(port: Int): Builder { return this } fun withListener(listener: Listener): Builder { return this } fun build() : MapApi { return MapApi(…) } } }
  23. class MapApi { object Builder { fun withHost(host: String): Builder

    { return this } fun withPort(port: Int): Builder { return this } fun withListener(listener: Listener): Builder { return this } fun build() : MapApi { return MapApi(…) } } } class Order { val mapApi: MapApi = MapApi.Builder.withHost(“http://droids4droids.com/places”) .withPort(23) .build() }
  24. class MapApi { object Builder { fun withHost(host: String): Builder

    { return this } fun withPort(port: Int): Builder { return this } fun withListener(listener: Listener): Builder { return this } fun build() : MapApi { return MapApi(…) } } } class Order { val mapApi: MapApi = MapApi.Builder.withHost(“http://droids4droids.com/places”) .withPort(23) .build() }
  25. class LoginRobot { fun writeEmail(text: String) { onView(withId(R.id.loginUsernameEditText)).perform(typeText(text), closeSoftKeyboard()) }

    fun writePassword(text: String) { onView(withId(R.id.loginUsernameEditText)).perform(typeText(text), closeSoftKeyboard()) } fun clickLoginButton(): MainRobot { onView(withId(R.id.loginSubmitButton)).perform(ViewActions.click()) return MainRobot() } }
  26. class LoginRobot { fun writeEmail(text: String): LoginRobot { onView(withId(R.id.loginUsernameEditText)).perform(typeText(text), closeSoftKeyboard())

    return this } fun writePassword(text: String): LoginRobot { onView(withId(R.id.loginUsernameEditText)).perform(typeText(text), closeSoftKeyboard()) return this } fun clickLoginButton(): MainRobot { onView(withId(R.id.loginSubmitButton)).perform(click()) return MainRobot() } }
  27. class LoginRobot { fun writeEmail(text: String): LoginRobot { onView(withId(R.id.loginUsernameEditText)).perform(typeText(text), closeSoftKeyboard())

    return this } fun writePassword(text: String): LoginRobot { onView(withId(R.id.loginUsernameEditText)).perform(typeText(text), closeSoftKeyboard()) return this } fun clickLoginButton(): MainRobot { onView(withId(R.id.loginSubmitButton)).perform(click()) return MainRobot() } }
  28. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") loginRobot.writePassword("[email protected]")

    val mainRobot = loginRobot.clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } Before
  29. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") loginRobot.writePassword("[email protected]")

    val mainRobot = loginRobot.clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } Before @Test fun test_login_showMainView() { val mainRobot = LoginRobot().writeEmail("[email protected]") .writePassword("007") .clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } After
  30. @Test fun test_login_showMainView() { val loginRobot = LoginRobot() loginRobot.writeEmail("[email protected]") loginRobot.writePassword("[email protected]")

    val mainRobot = loginRobot.clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } Before @Test fun test_login_showMainView() { val mainRobot = LoginRobot().writeEmail("[email protected]") .writePassword("007") .clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } After
  31. interface Book class PaperbackBook(val title: String, val author: String) :

    Book val book1 = PaperbackBook("Secret agents for Dummies", "James Bond") val book2 = PaperbackBook("Secret agents for Dummies", "James bond”) val book3 = PaperbackBook("Secret agents for Dummies", "James Bod")
  32. interface Book class PaperbackBook(val title: String, val author: String) :

    Book val book1 = PaperbackBook("Secret agents for Dummies", "James Bond") val book2 = PaperbackBook("Secret agents for Dummies", "James bond”) val book3 = PaperbackBook("Secret agents for Dummies", "James Bod")
  33. interface Book internal class PaperbackBook(val title: String, val author: String)

    : Book object PaperbackBookFactory { fun jamesBondBook(title: String): Book { return PaperbackBook(title, "James Bond"); } } val book = PaperbackBookFactory.jamesBondBook("Secret agents for Dummies”) val book2 = PaperbackBookFactory.jamesBondBook("Secret agents for Dummies 2”)
  34. interface Book internal class PaperbackBook(val title: String, val author: String)

    : Book object PaperbackBookFactory { fun jamesBondBook(title: String): Book { return PaperbackBook(title, "James Bond"); } } val book = PaperbackBookFactory.jamesBondBook("Secret agents for Dummies”) val book2 = PaperbackBookFactory.jamesBondBook("Secret agents for Dummies 2”)
  35. class MainTests {
 
 @Test
 fun test_onLogout_showLoginView() {
 val mainRobot

    = LoginRobot().writeEmail("[email protected]") .writePassword("007") .clickLoginButton() // Returns a MainRobot
 
 mainRobot.clickLogoutButton()
 
 loginRobot.checkIsVisible()
 } 
 } class LoginTests { @Test fun test_login_showMainView() { val mainRobot = LoginRobot().writeEmail("[email protected]") .writePassword("007") .clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } }
  36. class MainTests {
 
 @Test
 fun test_onLogout_showLoginView() {
 val mainRobot

    = LoginRobot().writeEmail("[email protected]") .writePassword("007") .clickLoginButton() // Returns a MainRobot
 
 mainRobot.clickLogoutButton()
 
 loginRobot.checkIsVisible()
 } 
 } class LoginTests { @Test fun test_login_showMainView() { val mainRobot = LoginRobot().writeEmail("[email protected]") .writePassword(“007") .clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } }
  37. class MainTests {
 
 @Test
 fun test_onLogout_showLoginView() {
 val mainRobot

    = LoginRobot().writeEmail("[email protected]") .writePassword("007") .clickLoginButton() // Returns a MainRobot
 
 mainRobot.clickLogoutButton()
 
 loginRobot.checkIsVisible()
 } 
 } class LoginTests { @Test fun test_login_showMainView() { val mainRobot = LoginRobot().writeEmail("[email protected]") .writePassword(“007") .clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } }
  38. class MainTests {
 
 @Test
 fun test_onLogout_showLoginView() {
 val mainRobot

    = LoginRobot().writeEmail("[email protected]") .writePassword("007") .clickLoginButton() // Returns a MainRobot
 
 mainRobot.clickLogoutButton()
 
 loginRobot.checkIsVisible()
 } 
 } class LoginTests { @Test fun test_login_showMainView() = loginSuccessfully { checkIsVisible() } }
  39. class MainTests {
 
 @Test
 fun test_onLogout_showLoginView() = loginSuccessfully {

    val loginRobot = clickLogoutButton()
 
 loginRobot.checkIsVisible()
 } 
 } class LoginTests { @Test fun test_login_showMainView() = loginSuccessfully { checkIsVisible() } }
  40. class MainTests {
 
 @Test
 fun test_onLogout_showLoginView() = loginSuccessfully {

    val loginRobot = this.clickLogoutButton() //this.class -> MainRobot
 
 loginRobot.checkIsVisible()
 } 
 } class LoginTests { @Test fun test_login_showMainView() = loginSuccessfully { this.checkIsVisible() //this.class -> MainRobot } }
  41. class MainTests {
 
 @Test
 fun test_onLogout_showLoginView() = loginSuccessfully {

    val loginRobot = clickLogoutButton()
 
 loginRobot.checkIsVisible()
 } 
 } class LoginTests { @Test fun test_login_showMainView() = loginSuccessfully { checkIsVisible() } }
  42. - Sample with/without robots: https://github.com/caipivara/androidmeetup-ui-robots - Realm / Jake Wharton:

    https://academy.realm.io/posts/kau-jake-wharton-testing-robots/ - Page Object: https://martinfowler.com/bliki/PageObject.html - Android Dialogs (Sam Edwards: Espresso Robots + Screenshots): https://www.youtube.com/watch? v=vsrX0gGZp3o - Icons: - https://www.iconfinder.com/icons/58995/lionel_preacherbot_robot_icon - https://www.iconfinder.com/icons/2624876/droid_r2d2_robot_starwars_icon - https://images.app.goo.gl/iNstLgWNeEYU9wfx6 - https://images.app.goo.gl/Sxvs9Qeswc4u7aBu7 - https://images.app.goo.gl/vsBjXbG8VTxTJ7tL8 - https://images.app.goo.gl/iFGnkhM16maDFA1N8 - https://images.app.goo.gl/K8zxQYzcRJ7HhAEEA - https://images.app.goo.gl/ZmPGc6FDuLK5o9GHA - https://images.app.goo.gl/12gAk8ynH4WwqAyW8 - https://images.app.goo.gl/4Cc8DTiVAjNRgJqs6 References