Android的长者preSSO如何使用APK编写测试? [英] Android Espresso how to write tests using apk?

查看:263
本文介绍了Android的长者preSSO如何使用APK编写测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个 robotium用户现在的切换到Es preSSO 谁能告诉我如何写在ES preSSO使用APK的测试,因为我们做的在robotium无需acccess到code,但使用的应用程序的apk。

I am a robotium user now switching to Espresso can anyone tell me how to write tests using apk in espresso, as we do in robotium without having acccess to the code but using app apk.

和如何访问看法,并没有R.id.viewid在ES preSSO?因为我们做robotium

And how to access views without R.id.viewid in espresso? as we do in robotium

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();
}
...

在ES preSSO

 @RunWith(AndroidJUnit4.class)
public class MainActivityTest {

// RecorderActivity is not accessible
@Rule public final ActivityRule<RecorderActivity> main = new ActivityRule<>(RecorderActivity.class);

@Test
public void launchMain(){

  }
}

如何指定类名?

推荐答案

您可以使用同样的反射技术来指定类 ActivityTestRule

You can use the same reflection technique to specify the class in ActivityTestRule:

@RunWith(AndroidJUnit4.class)
public class MainActivityTest {

  private static final String CLASSNAME = "com.rex.binderapps.RecorderActivity";

  private static Class<? extends Activity> activityClass;
  static {
    try {
      activityClass = (Class<? extends Activity>) Class.forName(CLASSNAME);
    } catch (ClassNotFoundException e) {
      throw new RuntimeException(e);
    }
  }

  @Rule 
  public final ActivityTestRule<?> activityRule 
      = new ActivityTestRule<>(activityClass);

  @Test
  public void launchMain() {

  }
}

这篇关于Android的长者preSSO如何使用APK编写测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆