【发布时间】:2015-04-29 14:39:42
【问题描述】:
我正在从robotium 切换到espresso,我正在使用apk 编写测试,我无法访问代码。 在robotium 中使用solo.getView("view-id") 我们可以访问视图,但我不知道如何在espresso 中进行操作? espresso witId() 方法需要我无权访问的 R.id.viewid。
public class AaEspressoTest {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.tri.re.CordActivity";
private static Class<?> launcherActivityClass;
static {
try {
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@Rule
public ActivityTestRule<?> mActivityRule = new ActivityTestRule(launcherActivityClass);
@Test public void testHello() throws Exception{
onView(withText("Browse older recordings")).perform(click());
//Id is not accessible shows red
onView(withId(R.id.button)).perform(click());
}
}
【问题讨论】:
-
如果你可以访问目标应用程序资源(通过上下文)你可以使用developer.android.com/reference/android/content/res/…中的
getIdentifier方法
标签: android junit4 robotium android-testing android-espresso