【问题标题】:Is there a method to catch the invoked method in Activity under testing with Espresso是否有一种方法可以在使用 Espresso 进行测试的 Activity 中捕获调用的方法
【发布时间】:2015-06-20 12:11:47
【问题描述】:

我将使用 Espresso 库编写测试代码。 但是,我找不到以下测试的解决方法。

测试模块是登录模块。 检查用户名和密码后,LoginActivity 会调用两个方法。

但是,我不知道如何捕获调用的方法......

下面是我的测试代码sn-p。

public class LoginActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {

public LoginActivityTest() {
    super(LoginActivity.class);
}

@Override
public void setUp() throws Exception {
    super.setUp();
    getActivity();
}



public void testLoginSuccess() {
    onView(withId(R.id.username)).perform(typeText("real@user.com"));
    onView(withId(R.id.password)).perform(typeText("secret"));
    onView(withId(R.id.loginButton)).perform(click());

    // I think I have to write code snippet down here.
}

}

登录活动有两个使用接口的回调方法。

@Override
public void loginSuccessful() {
    ...
}

@Override
public void showError() {
}

【问题讨论】:

  • 我已经更新了答案

标签: android testing junit mocking android-espresso


【解决方案1】:
猜你喜欢
  • 2019-04-04
  • 1970-01-01
  • 2022-07-10
  • 1970-01-01
  • 2014-12-13
  • 2014-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多