Samir Basnet
02/23/2021, 9:56 AMpackage com.view9.legalremit.ui.login
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import com.view9.legalremit.R
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class LoginActivityUiTest{
@Test
fun is_ActivityInView() {
val activityScenario = ActivityScenario.launch(LoginActivity::class.java)
onView(withId(R.id.container)).check(matches(isDisplayed()))
}
}
Above is my first Expresso test to check if an activity is in View. R.id.container here container is the id of the root layout of the Login Xml . But when i test it on my real Android device it fails with error: androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id is <com.view9.legalremit:id/container> . What am i doing wrong ?Samir Basnet
02/23/2021, 1:03 PM