Verify AlertDialog shown on invalid text input
I am writing tests for an android application by using ActivityInstrumentationTestCase2. And I would like to verify that an AlertDialog is shown when the input for an EditText is invalid.
The documentation says:
You can also verify that the Activity responds to invalid input by sett开发者_运维技巧ing error messages in the View.
http://androidappdocs.appspot.com/guide/topics/testing/activity_testing.html
I think this is what I need. But I can't find how. How can I do this?
Ok I found a solution.
First of all I downloaded Robotium.
After that I checked whether the AlertDialog is shown by checking the text it contains:
public void testEnterNumberEditBoxForInvalidNumber() {
solo.enterText(0, "1234567890123456");
solo.clickOnImageButton(0);
boolean actual = solo.searchText("The number entered is not valid.");
assertEquals(true, actual);
}
I'm open to better solutions. That's why I won't mark the question checked for a while.
精彩评论