【发布时间】:2015-04-27 12:23:58
【问题描述】:
我现在是 robotium 用户 切换到 Espresso 谁能告诉我如何在 espresso 中使用 apk 编写测试,就像我们在 robotsium 中所做的那样,无需访问代码但使用应用 apk。
以及如何在 espresso 中访问没有 R.id.viewid 的视图?就像我们在机器人中所做的那样
solo.getview("viewidText")
在robotium中我们就是这样做的
public class CoreTest extends ActivityInstrumentationTestCase2 {
private Solo solo;
//class name of the app launcher activity
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.rex.binderapps.RecorderActivity";
private static Class<?> launcherActivityClass;
static {
try {
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public CoreRecordingTest() throws ClassNotFoundException {
super(launcherActivityClass);
}
public void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation());
Test.setup(this);
getActivity();
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}
...
浓缩咖啡
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
// RecorderActivity is not accessible
@Rule public final ActivityRule<RecorderActivity> main = new ActivityRule<>(RecorderActivity.class);
@Test
public void launchMain(){
}
}
如何指定类名?
【问题讨论】:
-
UI Automator 更适合这种无源集成测试,恕我直言。
-
@CommonsWare 谢谢,我们有复杂的功能测试,用 ui automator 做那些是不可行的。我们有两个独立的项目,因此目前我们无法将 espresso 测试直接集成到主项目中,因此找到一种解决方法来使用 apk 编写测试,一旦测试项目准备就绪,我们将与主项目集成。
标签: android junit4 robotium android-testing android-espresso