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

One Espresso with Kotlin, please

One Espresso with Kotlin, please

GDG DevFest Thailand.
07/10/2017

Iñaki Villar

October 07, 2017
Tweet

More Decks by Iñaki Villar

Other Decks in Technology

Transcript

  1. #devfestbkk @RunWith(AndroidJUnit4.class) public class NotesActivityTest { @Rule public ActivityTestRule<Activity> activity

    = new ActivityTestRule<>(Activity.class); @Test public void notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  2. #devfestbkk @RunWith(AndroidJUnit4.class) public class NotesActivityTest { @Rule public ActivityTestRule<Activity> activity

    = new ActivityTestRule<>(Activity.class); @Test public void notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  3. #devfestbkk @RunWith(AndroidJUnit4.class) public class NotesActivityTest { @Rule public ActivityTestRule<Activity> activity

    = new ActivityTestRule<>(Activity.class); @Test public void notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  4. #devfestbkk @RunWith(AndroidJUnit4.class) public class NotesActivityTest { @Rule public ActivityTestRule<Activity> activity

    = new ActivityTestRule<>(Activity.class); @Test public void notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  5. #devfestbkk @RunWith(AndroidJUnit4.class) public class NotesActivityTest { @Rule public ActivityTestRule<Activity> activity

    = new ActivityTestRule<>(Activity.class); @Test public void notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } } onView check perform
  6. #devfestbkk @RunWith(AndroidJUnit4.class) public class NotesActivityTest { @Rule public ActivityTestRule<Activity> activity

    = new ActivityTestRule<>(Activity.class); @Test public void notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  7. #devfestbkk @RunWith(AndroidJUnit4::class) class NotesActivityTest { @Rule var activity = ActivityTestRule<NotesActivity>(NotesActivity::class.java)

    @Test fun notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  8. #devfestbkk @RunWith(AndroidJUnit4::class) class NotesActivityTest { @Rule var activity = ActivityTestRule<NotesActivity>(NotesActivity::class.java)

    @Test fun notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  9. #devfestbkk @RunWith(AndroidJUnit4::class) class NotesActivityTest { @Rule var activity = ActivityTestRule<NotesActivity>(NotesActivity::class.java)

    @Test fun notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  10. #devfestbkk @RunWith(AndroidJUnit4::class) class NotesActivityTest { @Rule var activity = ActivityTestRule<NotesActivity>(NotesActivity::class.java)

    @Test fun notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  11. #devfestbkk @RunWith(AndroidJUnit4::class) class NotesActivityTest { @Rule var activity = ActivityTestRule<NotesActivity>(NotesActivity::class.java)

    @Test fun notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  12. #devfestbkk @RunWith(AndroidJUnit4::class) class NotesActivityTest { @Rule var activity = ActivityTestRule<NotesActivity>(NotesActivity::class.java)

    @Test fun notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } } @RunWith(AndroidJUnit4.class) public class NotesActivityTest { @Rule public ActivityTestRule<Activity> activity = new ActivityTestRule<>(Activity.class); @Test public void notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); } }
  13. #devfestbkk apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion

    25 buildToolsVersion "26.0.0" defaultConfig { applicationId "bkk.firebase.com.myapplication" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
  14. #devfestbkk verticalLayout { padding = dip(32) imageView(android.R.drawable.ic_menu_manage).lparams { margin =

    dip(16) gravity = Gravity.CENTER } val name = editText { hintResource = R.string.name } val password = editText { hintResource = R.string.password inputType = TYPE_CLASS_TEXT or TYPE_TEXT_VARIATION_PASSWORD } button("Log in") { onClick { ui.owner.tryLogin(ui, name.text, password.text) } } myRichView() }.applyRecursively(customStyle)
  15. buttonSend.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ send(); } });

    buttonSend.setOnClickListener(object :OnClickListener{ override fun onClick(view : View){ send(); } }) #devfestbkk
  16. buttonSend.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ send(); } });

    buttonSend.setOnClickListener(object :OnClickListener{ override fun onClick(view : View){ send(); } }) buttonSend.setOnClickListener(View.OnClickListener { view : View -> doSomething() } #devfestbkk
  17. #devfestbkk /** * Calls the specified function [block] with `this`

    value as its receiver and returns `this` value. */ @kotlin.internal.InlineOnly public inline fun <T> T.apply(block: T.() -> Unit): T { block(); return this }
  18. #devfestbkk /** * Calls the specified function [block] with `this`

    value as its receiver and returns `this` value. */ @kotlin.internal.InlineOnly public inline fun <T> T.apply(block: T.() -> Unit): T { block(); return this } fun alphabet() = StringBuilder().apply { for (letter in 'A'..'Z') { append(letter) } append("\nNow I know the alphabet!") }.toString()
  19. #devfestbkk /** * Calls the specified function [block] with `this`

    value as its receiver and returns `this` value. */ @kotlin.internal.InlineOnly public inline fun <T> T.apply(block: T.() -> Unit): T { block(); return this } /** * Calls the specified function [block] with the given [receiver] as its receiver and returns its result. */ @kotlin.internal.InlineOnly public inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
  20. #devfestbkk /** * Calls the specified function [block] with `this`

    value as its receiver and returns `this` value. */ @kotlin.internal.InlineOnly public inline fun <T> T.apply(block: T.() -> Unit): T { block(); return this } /** * Calls the specified function [block] with the given [receiver] as its receiver and returns its result. */ @kotlin.internal.InlineOnly public inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block() fun alphabet() = with(StringBuilder()) { for (letter in 'A'..'Z') { append(letter) } append("\nNow I know the alphabet!") toString() }
  21. #devfestbkk infix fun <T: Fragment> T.execute(fn: T.() -> Unit) =

    this.fn() val myFragment = Fragment() myFragment execute { onPause() onDestroy() }
  22. #devfestbkk infix fun <T: Fragment> T.execute(fn: T.() -> Unit) =

    this.fn() val myFragment = Fragment() myFragment execute { onPause() onDestroy() }
  23. #devfestbkk @Test fun test() { screen { content { isVisible()

    } textViewLarge { click() isVisible() hasAnyText() } } }
  24. #devfestbkk class TestActivityScreen: Screen<TestActivityScreen>() val content: KView = KView {

    withId(R.id.content) } val textViewLarge: KTextView = KTextView { withId(R.id.text_view_small) }
  25. #devfestbkk @Test fun test() { screen { content { isVisible()

    } textViewLarge { click() isVisible() hasAnyText() } } }
  26. #devfestbkk @Test fun test() { screen { content { isVisible()

    } textViewLarge { click() isVisible() hasAnyText() } } } @Test fun notesActivityTest2() { onView(allOf(withParent(withId(R.id.my_button)),isDisplayed())) .perform(click()); }