I am writing some test for a project that I have been working on in which I have to test the buttons of an audio player. This is the code I have written
fun test {
val data = fakeAudioLibrary.initializeAudioPlayer() //here data is a livedata
launch<AudioFragmentTestActivity>(
createAudioFragmentTestIntent(
internalProfileId
)
).use {
it.onActivity {
data.observeForever{ } /*Problem here*/
}
onView(withId(R.id.ivPlayPauseAudio)).perform(click())
onView(withId(R.id.ivPlayPauseAudio)).check(matches(withContentDescription("Pause")
}
}
This test fails but when I write
it.onActivity {
data.observeForever {
if(it.isCompleted()) {
onView(withId(R.id.ivPlayPauseAudio)).perform(click())
onView(withId(R.id.ivPlayPauseAudio)).check(matches(withContentDescription("Pause")
}
}
I read about it here and I think it should work both ways.
Can someone please explain to me why this is happening?
question from:
https://stackoverflow.com/questions/65830617/testing-audio-player-on-espresso 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…