From 4416d87fbc5a3d52a4033fd74b42381247ac0629 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 19 Jan 2024 23:25:14 +0100 Subject: [PATCH] test: show the problem wrt waiting for an updated UI It still doesn't work, but perhaps this makes it easier to explain the problem. --- .../MainActivityInstrumentedTest.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityInstrumentedTest.kt b/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityInstrumentedTest.kt index 7d13c7b4..001c4c04 100644 --- a/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityInstrumentedTest.kt +++ b/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityInstrumentedTest.kt @@ -16,6 +16,7 @@ import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu import androidx.test.espresso.action.ViewActions.click +// import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.Intents.intending import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction @@ -42,7 +43,8 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class MainActivityInstrumentedTest { - @get:Rule + @JvmField + @Rule var activityScenarioRule = ActivityScenarioRule(MainActivity::class.java) @get:Rule @@ -68,10 +70,18 @@ class MainActivityInstrumentedTest { } @Test - fun testCountStat() = runBlocking { - onView(withId(R.id.start_stop)).perform(click()) - onView(withId(R.id.start_stop)).perform(click()) + fun testCountStat(): Unit = runBlocking { + val startStop = onView(withId(R.id.start_stop_layout)) + // Start. + startStop.perform(click()) + // Stop. + startStop.perform(click()) + + // Read number of created sleeps. assertEquals(1, database.sleepDao().getAll().size) + // FIXME UI is not yet updated, how to wait for this? + // val sleepsCount = onView(withId(R.id.fragment_stats_sleeps)) + // sleepsCount.check(matches(withText("1"))) } @Test