[英]Android UI Testing - Localized String testing
这是一个两部分的问题。
1 - 它是否为项目增加了价值,以检查每个字符串是否与跨多种语言的正确小部件匹配以进行 Activity 的关联 UI 测试,还是我应该采取不同的方法还是根本不这样做?
2 - 假设这是我尝试实施以下帖子中的建议的正确方法。 不幸的是,我的 UI 测试的语言环境没有更新,并且根据我已经在我的设备上设置的系统语言,这两个测试之一失败了。
@RunWith(AndroidJUnit4ClassRunner.class)
public class RegisterActivityTest {
@Test
public void test_onScreenLoadStringsDisplayedInEnglish() {
testEnglishLocale();
onView(withId(R.id.welcome_text_view)).check(matches(
withText(WELCOME_EN)));
}
@Test
public void test_onScreenLoadStringsDisplayedInSpanish() {
testSpanishLocale();
onView(withId(R.id.welcome_text_view)).check(matches(
withText(WELCOME_ES)));
}
private void testEnglishLocale() {
setLocale("en", "US");
}
private void testSpanishLocale() {
setLocale("es", "ES");
}
private void setLocale(String language, String country) {
Locale locale = new Locale(language, country);
// here we update locale for date formatters
Locale.setDefault(locale);
// update locale for app resources
Resources res = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
Configuration config = res.getConfiguration();
config.locale = locale;
res.updateConfiguration(config, res.getDisplayMetrics());
}
}
要回答您问题的第一部分,它确实增加了围绕不同语言进行测试的价值。 我们遇到的一个常见问题是 UI 是为本地语言设计的,但翻译语言的措辞通常比本地版本长。 这可能会导致意外的不良 UI 行为,例如按钮超出屏幕边缘,或内容被按下。 正是这些渲染问题非常适合测试。
我还不能评论第二个问题。 我刚刚开始研究如何在 espresso 中实现区域设置更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.