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

(kotlin + patterns ) _ ui-test = happy develope...

Daniel
August 18, 2018

(kotlin + patterns ) _ ui-test = happy developer DROIDS4DROIDS

Daniel

August 18, 2018
Tweet

More Decks by Daniel

Other Decks in Technology

Transcript

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

    Rico
 +danielgomezrico 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()))
 } Login test on
  8. @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()))
 }
  9. @Test fun test_login_showMainView() { // write email // write password

    // click login button // check if user logged in successfully } Login test
  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]") 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())) }
  12. @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())) }
  13. @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())) }
  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 Espresso.onView(AllOf.allOf(ViewMatchers.withText("Main"))) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) }
  17. @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())) }
  18. 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
  19. open class BaseRobot { fun click(id: Int) { onView(withId(id)).perform(ViewActions.click()) }

    } class LoginRobot : BaseRobot() { fun clickLogin() { click(R.id.loginButton) } }
  20. 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) } }
  21. 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) }
  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(…) } } }
  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 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() }
  26. 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() } }
  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. 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() } }
  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
  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. @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
  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 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")
  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. 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”)
  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() { val mainRobot = LoginRobot().writeEmail("[email protected]") .writePassword(“007") .clickLoginButton() // Returns a MainRobot mainRobot.checkIsVisible() } }
  39. 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() } }
  40. class MainTests {
 
 @Test
 fun test_onLogout_showLoginView() = loginSuccessfully {

    val loginRobot = clickLogoutButton()
 
 loginRobot.checkIsVisible()
 } 
 } class LoginTests { @Test fun test_login_showMainView() = loginSuccessfully { checkIsVisible() } }
  41. 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 } }
  42. class MainTests {
 
 @Test
 fun test_onLogout_showLoginView() = loginSuccessfully {

    val loginRobot = clickLogoutButton()
 
 loginRobot.checkIsVisible()
 } 
 } class LoginTests { @Test fun test_login_showMainView() = loginSuccessfully { checkIsVisible() } }
  43. - Speak Sample: 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 References