Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

android - Testing audio player on espresso

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...