简体   繁体   中英

What is the best way to reference resource identifiers in UIAutomator tests?

I recently started using UIautomator for testing of my Android apps.

The following code fragment shows a typical statement within the code of the test cases:

mDevice.findObject(By.res(BASIC_SAMPLE_PACKAGE, "editTextUserInput"))
                .setText(STRING_TO_BE_TYPED);

As you can see, the "editTExtUserInput" is referenced as a string. In my applications source code this is defined as a resource identifier (R.id.editTextUserInput).

In the current situation, when I will change the name of the identifier in my app, all my test cases would get messed up (I will have to change all string values by hand)... Does anyone have a solution for this issue?

Much of Google's Android Testing team has been spending time building Espresso , a new UI testing framework which specifically makes these cases easier. For example, the line could be

onView(withId(R.id.editTextUserInput)).typeText(STRING_TO_BE_TYPED);

And things like identifier autocomplete and refactoring would also affect these tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM