【问题标题】:Better Android Automated Test Performance using Expresso?使用 Expresso 获得更好的 Android 自动测试性能?
【发布时间】:2014-02-20 07:49:05
【问题描述】:

在研究了 Android 的自动化测试框架后,我偶然发现了 Espresso。它似乎拥有我想要的一切:可靠的测试、最少的样板代码、更高的性能。

我观看了演示 Espresso 的 GTAC 2013 演示文稿,并且很高兴看到它运行测试的速度有多快。然而,在实际实现了一些测试之后,我必须说我并没有注意到太多,如果使用标准 Android 测试框架有任何性能优势的话。我没有做过任何形式的“官方”基准测试,但我的理解是 Espresso 颠覆了标准的 Android 测试框架。

我正在测试的项目是 developer.android.com 上的教程中描述的项目。我正在编写的测试非常简单:

@Test
public void test_sendButton_shouldInitiallyBeDisabled() {
    onView(withId(R.id.button_send)).check(matches(not(ViewMatchers.isEnabled())));
}

@Test
public void test_sendButton_shouldBeEnabledAfterEnteringText() {
    String enteredText = "This is my message!";
    // Type Text 
    onView(withId(R.id.edit_message)).perform(ViewActions.typeText(enteredText));

    // Validate the Result
    onView(withId(R.id.button_send)).check(matches(ViewMatchers.isEnabled()));
}

@Test
public void test_enteringTextAndPressingSendButton_shouldDisplayEnteredText() {
    String enteredText = "This is my message!";
    // Type Text 
    onView(withId(R.id.edit_message)).perform(ViewActions.typeText(enteredText));

    // Click Button
    onView(withId(R.id.button_send)).perform(click());

    // Validate the Results
    onView(withId(R.id.display_message)).check(ViewAssertions.matches(ViewMatchers.withText(enteredText)));
}

我按照 Espresso 网站上的所有说明进行操作,特别注意我的运行配置使用了 GoogleInstrumentationTestRunner。

那么我错过了什么?我只是错过了一些简单的事情吗?还是我关于显着提高性能的假设完全错误?

【问题讨论】:

    标签: android android-espresso


    【解决方案1】:

    对于非常简单的测试,您可能不会注意到与标准仪器有很大差异这一事实。对于连续运行(即必须稳定)的更复杂的测试(例如跨越多个活动的测试),人们通常最终会添加睡眠/重试逻辑以防止出现不稳定。使用 Espresso,您可以消除它并享受测试运行时间的显着减少。这是一个G+ post,显示了 Espresso 与 Robotium 测试的比较。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-29
      • 2021-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-13
      • 2011-11-26
      相关资源
      最近更新 更多