浓缩咖啡 android 测试

Espresso android testing

如何在特定 activity 中开始我的测试?假设我正在我的应用程序中测试收藏夹选项卡,但我希望我的测试在登录屏幕上开始,我将使用什么方法来做到这一点?我在任何地方都找不到任何关于它的信息,我确信这只是一个简单的电话。

您必须先将要启动的 activity 提供到 ActivityTestRule 中,然后登录,导航到收藏夹并对其进行测试:

@RunWith(AndroidJUnit4.class)
public class TestFavorites {

    @Rule
    public ActivityTestRule<LoginActivity> mActivityRule = new ActivityTestRule(LoginActivity.class);

    @Before
    public void setUp() {
        //your setUp
    }

    @Test
    public void testSaveOtherContactToPhoneContacts() {
        logInUser(); //do the login
        //navigate to the favorites tab and test it
    }

    @After
    public void tearDown() {
        //your tearDown
    }
}

闲置时,您应该在仪器测试中测试单个 activity。如果您想测试整个流程,请选择 automation testing using calabash。 在仪器测试中,您可以使用不同的数据集测试单个 activity,速度会快得多。

不过,如果您想在检测中测试整个流程,那么您可以在 ActivityTestRule.

中提供 activity