mardi 17 décembre 2019

Robolectric Test for ProgressDialog in android

I have 2 methods

public void showProgress() {
    progressDialog = ProgressDialog.show(LoanDemandDetails.this, "", resourceUtil.getLabelById(R.string.uploading_loan_demand), true, false);
}

and

public void onHideProgressDialog() {
    progressDialog.hide();
}

now i want to test these functions using Robolectric.

i've written test case for showProgress and it passed

the test code looks like

@Test
public void showProgressDialog() {
    activity.showProgress();

    ProgressDialog dialog = (ProgressDialog) ShadowProgressDialog.getLatestDialog();

    assertEquals("Uploading Loan Demand...", shadowOf(dialog).getMessage());


}

and Similarly when i test for hideProgressDialog it fails

the code looked like this:

@Test
public void hideProgressDialog(){
    activity.showProgress();

    activity.onHideProgressDialog();
    ProgressDialog dialog1 = (ProgressDialog) ShadowProgressDialog.getLatestDialog();
    assertFalse(dialog1.isShowing());
}

Aucun commentaire:

Enregistrer un commentaire