Android Espresso testing slow and buggy execution

Viewed 149

I'm following this tutorial on Android development... But I'm having weird happen (or at least I think it's weird), while running tests the app doesn't open itself (which I don't think is normal), and when I open it, it starts doing the test, but then it opens a screen that looks like this:

enter image description here

And it stays like that for almost a full minute, before closing and going to the next test (where I again have to open the the app before it starts the test)... This can't be normal, right? For one small test to take longer than a minute?

I use a Xiaomi Redmi 9T (Real device, not emulator).

My tests:

package com.mypkg.tiptime

import ...

@RunWith(AndroidJUnit4::class)
class CalculatorTests {
    @get:Rule()
    val activity = ActivityScenarioRule(MainActivity::class.java)

    @Test
    fun calculate_20_percent_tip() {
        // enter text into the service text edit
        onView(withId(R.id.cost_of_service_edit_text))
            .perform(typeText("50.00"))

        // click the calculate button
        onView(withId(R.id.calculate_button))
            .perform(click())

        onView(withId(R.id.tip_result))
            .check(matches(withText(containsString("$10.00"))))
    }

    @Test
    fun calculate_18_percent_tip_no_roundup() {
        // enter text into the service text edit
        onView(withId(R.id.cost_of_service_edit_text))
            .perform(typeText("182"))

        onView(withId(R.id.option_eighteen_percent))
            .perform(click())

        onView(withId(R.id.round_up_switch))
            .perform(click())

        // click the calculate button
        onView(withId(R.id.calculate_button))
            .perform(click())

        onView(withId(R.id.tip_result))
            .check(matches(withText(containsString("$32.76"))))
    }
}

I'm new to Android dev, so maybe I'm not understanding it correctly? Or it can be a Xiaomi thing? My PC is too slow to run an emulator + Android Studio at the same time, so I cannot test it out on an emulator :/

Thank you in advance :)

0 Answers
Related