我正在为一个通过NFC标签与仪器交互的android应用程序编写Espresso自动化测试。在NFC阅读和与仪器的手动交互过程中,我想暂停浓咖啡测试3-4分钟。在浓咖啡测试期间,我们能同时进行自动化和手动交互吗?空闲资源是否是一个选项,因为在暂停期间会发生UI更改?
发布于 2015-12-08 07:30:35
好吧,我不知道同时进行自动化测试和手动测试的想法,理论上自动化测试应该加快使用app检查用户交互的过程,并简化手工测试人员的某些工作。
在运行自动化Espresso测试的过程中进行手动测试确实是个坏主意。中断测试或更改app状态非常容易,这会导致测试失败。
在上一次谷歌测试自动化大会上,2015年宣布了咖啡师 - 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测试运行程序,因为我们将在测试配置中使用JUnit4
最后,像这样修改测试类代码:
@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
}应该管用的。
发布于 2016-04-20 07:41:49
我没有仔细考虑,但是创建自己的ViewAction可以停止测试,如下所示:
onView(withText(R.string.some_text)).perform(wait(3 *60);
https://stackoverflow.com/questions/34052002
复制相似问题