【发布时间】:2015-08-06 11:00:14
【问题描述】:
我在做什么:我正在使用 Robotium 测试一个 Android 应用程序。
什么有效:如果我用一种测试方法进行测试,一切都很好
什么不起作用:如果我尝试将此测试分成两个较小的测试,那么第一个测试通过,第二个测试挂起(或冻结 - 我不知道如何命名)
为什么我需要它我需要它来在 sppon 中显示每个测试的条形报告(我将拥有:testLogin、testAddCustomer、testLogout 等)。勺子报告示例如下所示:
如果我有一个大测试 (testAll),则只有一个大绿色条,但我需要为每种测试方法设置许多短条,如上图所示。
我做了什么:我已经阅读了很多关于类似问题的不同主题,但对我没有帮助
这是一个简短的例子,说明什么是有效的(一种方法 - testAll())我在 cmets 中编写了 currents 活动:
public class LogInLogOut extends ActivityInstrumentationTestCase2 {
private Solo solo;
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "mobile.touch.core.activity.SplashScreenActivity";
private static Class<?> launcherActivityClass;
static {
try {
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public LogInLogOut() throws ClassNotFoundException {
super(launcherActivityClass);
}
public void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation());
getActivity();
}
@Override
protected void tearDown() throws Exception {
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
public void testAll() {
// here is LoginActivity <<-----
// username
solo.clickOnView(solo.getView(0x3));
solo.enterText((android.widget.EditText) solo.getView(0x3), "user");
// enter password
solo.clickOnView(solo.getView(0x3, 1));
solo.enterText((android.widget.EditText) solo.getView(0x3, 1), "password");
// click on log in button
solo.clickOnView(solo.getView(android.widget.Button.class, 0));
// here ContainerActivity starts <<-----
//click on log out
solo.clickOnMenuItem("LogOut");
}
}
使用 testAll () 方法可以通过所有测试。但我需要将其分为 testLogin() 和测试 testLogout()。
这是我如何将metod testAll分成两个较小的(testLogin() & testLogout()):
public void testLogin() {
// here is LoginActivity <<-----
// username
solo.clickOnView(solo.getView(0x3));
solo.enterText((android.widget.EditText) solo.getView(0x3), "user");
// enter password
solo.clickOnView(solo.getView(0x3, 1));
solo.enterText((android.widget.EditText) solo.getView(0x3, 1), "password");
// click on log in button
solo.clickOnView(solo.getView(android.widget.Button.class, 0));
// here ContainerActivity starts <<-----
}
public void testOut() {
//click on log out
solo.clickOnMenuItem("LogOut");
}
现在第一个测试 (testLogin()) 已通过,第二个测试 (testLogout()) 挂起
为了检查测试是否开始,我输入了日志。
public void testOut() {
Log.i("checkTestB", "test B started"); <<-- here is the log
//click on log out
solo.clickOnMenuItem("LogOut");
}
发生testLog没有执行代码,因为“test B started”不在日志中
问题:我该如何解决这个问题?
【问题讨论】:
标签: android unit-testing automated-tests ui-automation robotium