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

Build Testble Apps for Androidの紹介 / introduce-b...

Build Testble Apps for Androidの紹介 / introduce-build-testable-apps-for-android

DeNA.apk#1 【Google I/O 報告会】の発表資料です
https://dena.connpass.com/event/128184/

tkmnzm

May 16, 2019
Tweet

More Decks by tkmnzm

Other Decks in Programming

Transcript

  1. E2E Test Code @Test fun createTask() { // start up

    Tasks screen val ac=vityScenario = Ac=vityScenario.launch(TasksAc=vity::class.java) dataBindingIdlingResource.monitorAc=vity(ac=vityScenario) // Click on the "+" bu\on, add details, and save onView(withId(R.id.fab_add_task)).perform(click()) onView(withId(R.id.add_task_=tle)).perform(typeText("=tle")) onView(withId(R.id.add_task_descrip=on)).perform(typeText("descrip=on")) onView(withId(R.id.fab_save_task)).perform(click()) // Then verify task is displayed on screen onView(withText("=tle")).check(matches(isDisplayed())) }
  2. E2E Test Code @Test fun createTask() { // start up

    Tasks screen val ac=vityScenario = Ac=vityScenario.launch(TasksAc=vity::class.java) dataBindingIdlingResource.monitorAc=vity(ac=vityScenario) // Click on the "+" bu\on, add details, and save onView(withId(R.id.fab_add_task)).perform(click()) onView(withId(R.id.add_task_=tle)).perform(typeText("=tle")) onView(withId(R.id.add_task_descrip=on)).perform(typeText("descrip=on")) onView(withId(R.id.fab_save_task)).perform(click()) // Then verify task is displayed on screen onView(withText("=tle")).check(matches(isDisplayed())) } Ac=vityΛىಈ͠
 ෳ਺ͷFragmentʹ·͕ͨͬͯ ϑϩʔΛݕূ
  3. Integra=on Test Code @Test fun validTask_isSaved() { // GIVEN -

    On the "Add Task" screen. val navController = mock(NavController::class.java) val bundle = AddEditTaskFragmentArgs(null, getApplica=onContext<Context>().getString(R.string.add_task)).toBundle() val scenario = launchFragmentInContainer<AddEditTaskFragment>(bundle, R.style.AppTheme) scenario.onFragment { Naviga=on.setViewNavController(it.view!!, navController) }
 .. } FragmentΛىಈ͠
 ϞοΫͷNavControllerΛ
 ౉͢
  4. Integra=on Test Code @Test fun validTask_isSaved() {
 .. // WHEN

    - Valid =tle and descrip=on combina=on and click save onView(withId(R.id.add_task_=tle)).perform(replaceText("=tle")) onView(withId(R.id.add_task_descrip=on)).perform(replaceText("descrip=on")) onView(withId(R.id.fab_save_task)).perform(click()) .. }
  5. Integra=on Test Code @Test fun validTask_isSaved() { .. // THEN

    - Verify that the repository saved the task val tasks = (repository.getTasksBlocking(true) as Result.Success).data assertEquals(tasks.size, 1) assertEquals(tasks[0].=tle, "=tle") verify(navController).navigate( AddEditTaskFragmentDirec=ons .ac=onAddEditTaskFragmentToTasksFragment(ADD_EDIT_RESULT_OK)) } Fake͔ΒσʔλΛ औಘͯ͠ݕূ

  6. Integra=on Test Code @Test fun validTask_isSaved() { .. // THEN

    - Verify that the repository saved the task val tasks = (repository.getTasksBlocking(true) as Result.Success).data assertEquals(tasks.size, 1) assertEquals(tasks[0].=tle, "=tle") verify(navController).navigate( AddEditTaskFragmentDirec=ons .ac=onAddEditTaskFragmentToTasksFragment(ADD_EDIT_RESULT_OK)) } ਖ਼͍͠ύϥϝʔλͰNaviga=on Ͱ͖͍ͯΔ͔ݕূ
  7. Nitrogen͕ϦϦʔε͞ΕΔ·Ͱ android { sourceSets { String sharedTestDir = 'src/sharedTest/java' test

    { java.srcDir sharedTestDir } androidTest { java.srcDir sharedTestDir } }