使用下面的代码,测试不会按我想要的顺序执行。test_homescreen 在 test_splashscreen 之前执行。
我想指定要运行的测试及其执行顺序。我相信我需要创建一个测试套件,但我不知道如何实现它。
package com.myapp.test;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import com.myapp.R;
public class myTest extends ActivityInstrumentationTestCase2{
private static final String TARGET_PACKAGE_ID="com.myapp.test";
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.myapp.gui.SplashScreen";
private static Class launcherActivityClass;
static{
try
{
launcherActivityClass=Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e){
throw new RuntimeException(e);
}
}
public myTest ()throws ClassNotFoundException{
super(TARGET_PACKAGE_ID,launcherActivityClass);
}
private Solo solo;
@Override
protected void setUp() throws Exception{
solo = new Solo(getInstrumentation(),getActivity());
}
public void test_splashscreen() throws InterruptedException {
TextView splashAppVersion = (TextView) solo.getView(R.id.AppVersion);
assertTrue(splashAppVersion.isShown());
}
public void test_homescreen() throws InterruptedException {
ListView lv = (ListView) solo.getView(R.id.List);
assertTrue(lv.isShown());
}
@Override
public void tearDown() throws Exception {
try {
solo.finishOpenedActivities();
} catch (Throwable e) {
e.printStackTrace();
}
super.tearDown();
}
}
先执行 test_splashscreen(),然后执行 test_homescreen()
只执行 test_homescreen()
这篇文章似乎与我想要的很接近,但我无法使用它。太笼统了。Android Robotium - 如何管理测试用例的执行顺序?