Adnroid studio 3.3.
In my app I use Retrofit to do http request. Also I use MockWebServer to return stub response.
On activity when I click button I start async http request (by Retrofit) and wait callback method to return response. Here Espresso's test:
@RunWith(AndroidJUnit4::class)
class AddTraderActivityTest {
@get:Rule
var addTraderIntentTestRule: IntentsTestRule<AddTraderActivity> = IntentsTestRule(AddTraderActivity::class.java)
@Before
fun setup() {
mockServer = MockWebServer()
mockServer.start(8081)
Debug.d(TAG, "SUCCCESS_START_MOCKWEBSRVER")
}
@Test
fun buttonStart_click_longResponse() {
// stub response
mockServer.enqueue(MockResponse()
.setResponseCode(200)
.setBody(FileUtil.getStringFromFile(context, "add_trader_success_200.json"))
.setBodyDelay(5000, TimeUnit.MILLISECONDS))
onView(withId(R.id.baseTextInputEditText))
.perform(typeText(BASE_TEST))
onView(withId(R.id.quoteTextInputEditText))
.perform(typeText(QUOTE_TEST))
onView(withId(R.id.startButton))
.perform(click())
onView(withText(R.id.containerProgressBarLayout))
.check(matches(isDisplayed()))
}
But problem is when execute perform(click()
the method check
is not call until not get stub response (after 5 seconds).
But I need call method check
immediately after perform(click()
method. Because I need to check
is containerProgressBarLayout
is isDisplayed()
while not return stub response. I need to check my view DURING loading data
How I can do this?