Share
Embed
Transcript
68 slides
-
(Kotlin + patterns) * ui-tests = happy developer Daniel Gomez
Rico @aquicaipivara Android Lead Developer at Barista Ventures -
@Test fun test_login_showMainView() { // write email // write password
// click login button // check if user logged in successfully } Test login works -
@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 -
@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 -
@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 -
@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 -
@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())) } -
@Test fun test_login_showMainView() { // write email // write password
// click login button // check if user logged in successfully } Login test -
@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())) } -
@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())) } -
@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())) } -
@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())) } -
@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())) } -
@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())) } -
@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())) } -
@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())) } -
@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())) } -
@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() { 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() { 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() { 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())) } -
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 -
open class BaseRobot { fun click(id: Int) { onView(withId(id)).perform(ViewActions.click()) }
} class LoginRobot : BaseRobot() { fun clickLogin() { click(R.id.loginButton) } } -
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) } } -
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) } -
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 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 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() } -
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() } -
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 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() } } -
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() } } -
@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 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 -
@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 -
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") -
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") -
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”) -
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”) -
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() } } -
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() } } -
fun loginSuccessfully(func: MainRobot.() -> Unit) { val mainRobot = LoginRobot().writeEmail("[email protected]")
.writePassword("007") .clickLoginButton() mainRobot.func() } -
fun loginSuccessfully(func: MainRobot.() -> Unit) { val mainRobot = LoginRobot().writeEmail("[email protected]")
.writePassword("007") .clickLoginButton() mainRobot.func() } -
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() } } -
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() } } -
class MainTests { @Test fun test_onLogout_showLoginView() = loginSuccessfully {
val loginRobot = clickLogoutButton() loginRobot.checkIsVisible() } } class LoginTests { @Test fun test_login_showMainView() = loginSuccessfully { checkIsVisible() } } -
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 } } -
class MainTests { @Test fun test_onLogout_showLoginView() = loginSuccessfully {
val loginRobot = clickLogoutButton() loginRobot.checkIsVisible() } } class LoginTests { @Test fun test_login_showMainView() = loginSuccessfully { checkIsVisible() } } -
- 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