You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 (call.enqueue(callback);) http request (by Retrofit 2) 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)
private val baseEditText = viewWithId(baseTextInputEditText)
private val quoteEditText = viewWithId(quoteTextInputEditText)
private val buttonStart = viewWithId(startButton)
@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.
So to do this I try this:
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 (
call.enqueue(callback);
) http request (by Retrofit 2) and wait callback method to return response. Here Espresso's test: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 afterperform(click())
method. Because I need to check iscontainerProgressBarLayout
isisDisplayed()
while not return stub response. I need to check my view DURING loading data.So to do this I try this:
But log
AFTER_CLICK
and methodcheckCondition()
call AFTER 5 SECONDS.When call
click
then call this production code:and this:
The text was updated successfully, but these errors were encountered: