嗯,我不明白同时进行自动化和手动测试的想法,理论上自动化测试应该加快检查用户与应用交互的过程,并减轻手动测试人员的一些工作。
在运行自动化 Espresso 测试的过程中进行手动测试确实是个坏主意。很容易中断测试或更改应用程序的状态,这会导致测试失败。
在上一次 2015 年 Google 测试自动化大会上宣布了 Barista - Espresso 测试记录器。
在 Espresso 中,我看到了三种可能的以您的方式进行测试的方法:
- 制作自定义空闲资源类并注册。
- 使用像
Thread.sleep(240000);这样的Java空闲方法
- 编写所有你想要的自动化测试,运行它们。最后做
选定的手动测试。
编辑:根据您的问题,最好的办法是使用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
}
它应该可以工作。