Skip to content

Commit affd646

Browse files
committed
테스트 - espresso 테스트 작성
1. espresso로 테스트 작성 2. Active Task UI 테스트 작성 3. Completed Task UI 테스트 작성
1 parent f2bdb4e commit affd646

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailFragmentTest.kt

+37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package com.example.android.architecture.blueprints.todoapp.taskdetail
22

33
import androidx.fragment.app.testing.launchFragmentInContainer
4+
import androidx.test.espresso.Espresso.onView
5+
import androidx.test.espresso.assertion.ViewAssertions.matches
6+
import androidx.test.espresso.matcher.ViewMatchers.isChecked
7+
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
8+
import androidx.test.espresso.matcher.ViewMatchers.withId
9+
import androidx.test.espresso.matcher.ViewMatchers.withText
410
import androidx.test.ext.junit.runners.AndroidJUnit4
511
import androidx.test.filters.MediumTest
612
import com.example.android.architecture.blueprints.todoapp.R
@@ -10,6 +16,7 @@ import com.example.android.architecture.blueprints.todoapp.data.source.TasksRepo
1016
import com.example.android.architecture.blueprints.todoapp.data.source.androidTest.FakeAndroidTestRepository
1117
import kotlinx.coroutines.ExperimentalCoroutinesApi
1218
import kotlinx.coroutines.test.runBlockingTest
19+
import org.hamcrest.Matchers.not
1320
import org.junit.After
1421
import org.junit.Assert.*
1522
import org.junit.Before
@@ -43,5 +50,35 @@ class TaskDetailFragmentTest {
4350
// WHEN - Details fragment launched to display task
4451
val bundle = TaskDetailFragmentArgs(activeTask.id).toBundle()
4552
launchFragmentInContainer<TaskDetailFragment>(bundle, R.style.AppTheme)
53+
54+
// THEN - Task details are displayed on the screen
55+
// make sure that the title/description are both shown and correct
56+
onView(withId(R.id.task_detail_title_text)).check(matches(isDisplayed()))
57+
onView(withId(R.id.task_detail_title_text)).check(matches(withText("Active Task")))
58+
onView(withId(R.id.task_detail_description_text)).check(matches(isDisplayed()))
59+
onView(withId(R.id.task_detail_description_text)).check(matches(withText("AndroidX Rocks")))
60+
// and make sure the "active" checkbox is shown unchecked
61+
onView(withId(R.id.task_detail_complete_checkbox)).check(matches(isDisplayed()))
62+
onView(withId(R.id.task_detail_complete_checkbox)).check(matches(not(isChecked())))
63+
}
64+
65+
@Test
66+
fun completedTaskDetails_DisplayedInUi() = runBlockingTest{
67+
// GIVEN - Add completed task to the DB
68+
val activeTask = Task("Completed Task", "AndroidX Rocks", true)
69+
repository.saveTask(activeTask)
70+
71+
// WHEN - Details fragment launched to display task
72+
val bundle = TaskDetailFragmentArgs(activeTask.id).toBundle()
73+
launchFragmentInContainer<TaskDetailFragment>(bundle, R.style.AppTheme)
74+
75+
// THEN - Task details are displayed on the screen
76+
onView(withId(R.id.task_detail_title_text)).check(matches(isDisplayed()))
77+
onView(withId(R.id.task_detail_title_text)).check(matches(withText("Completed Task")))
78+
onView(withId(R.id.task_detail_description_text)).check(matches(isDisplayed()))
79+
onView(withId(R.id.task_detail_description_text)).check(matches(withText("AndroidX Rocks")))
80+
// make sure that the title/description are both shown and correct
81+
onView(withId(R.id.task_detail_complete_checkbox)).check(matches(isDisplayed()))
82+
onView(withId(R.id.task_detail_complete_checkbox)).check(matches(isChecked()))
4683
}
4784
}

0 commit comments

Comments
 (0)