【问题标题】:Espresso automated and manual test at the same time同时进行 Espresso 自动和手动测试
【发布时间】:2015-12-02 20:05:16
【问题描述】:

我正在为一个通过 NFC 标签与仪器交互的 Android 应用程序编写 Espresso 自动化测试。在 NFC 读取和与仪器的手动交互期间,我想暂停 espresso 测试 3-4 分钟。我们可以在意式浓缩咖啡测试期间同时进行自动和手动交互吗?是否可以选择空闲资源,因为在暂停期间会有 UI 更改?

【问题讨论】:

  • 您找到了解决这个问题的适当方法吗?我也想知道。

标签: android testing manual android-espresso


【解决方案1】:

嗯,我不明白同时进行自动化和手动测试的想法,理论上自动化测试应该加快检查用户与应用交互的过程,并减轻手动测试人员的一些工作。

在运行自动化 Espresso 测试的过程中进行手动测试确实是个坏主意。很容易中断测试或更改应用程序的状态,这会导致测试失败。

在上一次 2015 年 Google 测试自动化大会上宣布了 Barista - Espresso 测试记录器。

在 Espresso 中,我看到了三种可能的以您的方式进行测试的方法:

  1. 制作自定义空闲资源类并注册。
  2. 使用像Thread.sleep(240000);这样的Java空闲方法
  3. 编写所有你想要的自动化测试,运行它们。最后做 选定的手动测试。

编辑:根据您的问题,最好的办法是使用Thead.sleep(milliseconds)。它将停止测试所需的时间,例如 3 或 4 分钟。

但 Espresso 测试以随机顺序运行,因此请重新配置您现有的配置,如下所示:

build.gradle 中声明android -> defaultConfig 你的testInstrumentationRunner,当然还有Espresso,所以你的Gradle 文件应该包含:

android {
 defaultConfig {
   testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
           }
        }
    
 dependencies {  
   androidTestCompile 'com.android.support:support-annotations:23.+'
   androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
   androidTestCompile 'com.android.support.test:runner:0.4.1'
   androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
    /**
     * AccessibilityChecks
     * CountingIdlingResource
     * DrawerActions
     * DrawerMatchers
     * PickerActions (Time and Date picker)
     * RecyclerViewActions
     */
    } 

注意:这里最重要的是声明 AndroidJUnitRunner 为您的 Espresso 测试运行器,因为我们将在我们的 测试配置

最后像这样改变你的测试类代码:

 @RunWith(AndroidJUnit4.class)
 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 
 public class EspressoExampleTest {

 @Rule
 public ActivityTestRule<MainActivity> mRule = new ActivityTestRule<>(MainActivity.class);

 @Test
 public void checkIfAppNameIsDisplayed() {
     onView(withText(R.string.app_name)).check(matches(isDisplayed()));
 }

在这里使用@FixMethodOrder(MethodSorters.NAME_ASCENDING) 会让你的测试类一步一步地执行,所以假设在你的第 8 个测试类之后你会放

 @Test
 public void waitUntilManualTestWoulBeDone() {
     Thread.sleep(1440000); //sleeps 4 minutes
 }

它应该可以工作。

【讨论】:

【解决方案2】:

我没有仔细考虑,但创建自己的 ViewAction 可能会停止测试,如下所示:

onView(withText(R.string.some_text)).perform(wait(3 * 60));

【讨论】:

    猜你喜欢
    • 2010-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多