2014-10-07 21 views
0

我通過Robotium檢查屏幕上的方法文本:如何檢查消息的正確性,取決於Android上使用的語言?

assertTrue(solo.waitForText("Wrong password")); 

assertTrue(solo.searchText("Wrong password")); 

然而,我的應用程序可以在幾種語言的工作,並在同一時間,在指定的語言工作Android作爲使用的語言。應用程序是用Java編寫的。如何檢查消息的正確性,取決於Android上使用的語言?

+1

你就不能使用'context.getResources()的getString(R.string.wrongpass)'? – 2014-10-07 11:35:58

回答

0

如果你想獲得本地化String不改變當前的配置(API> = 17):

Configuration config = new Configuration(context.getResources().getConfiguration()); 
config.setLocale(locale); 
return context.createConfigurationContext(config).getText(resId); 

其中locale是您要測試的對象之一。

如果你的目標較低API級別:

Configuration conf = context.getResources().getConfiguration(); 
conf.locale = new Locale("de"); 
// Then update resources based on this Configuration. 
context.getResources().updateConfiguration(conf, context.getResources().getDisplayMetrics()); 
// Afterwards, resources will retrieve localised strings instead of default locale 
String deLocaleString = context.getResources().getString(R.string.my_string); 
相關問題