Espresso 自动和手动同时测试
Espresso automated and manual test at the same time
我正在为 android 应用程序编写 Espresso 自动化测试,该应用程序通过 NFC 标签与仪器交互。在 NFC 读取和与仪器的手动交互期间,我想将浓缩咖啡测试暂停 3-4 分钟。我们可以在浓缩咖啡测试期间同时进行自动和手动交互吗?是否可以选择闲置资源,因为在暂停期间会有 UI 变化?
好吧,我不明白同时进行自动化和手动测试,理论上自动化测试应该加快检查用户与应用程序交互的过程,并减轻手动测试人员的一些工作。
在 运行 自动 Espresso 测试中间进行手动测试确实是个坏主意。中断测试或更改应用程序状态非常容易,这会导致测试失败。
上次 Google 宣布了 2015 年测试自动化大会 Barista - Espresso 测试的记录器。
在 Espresso 中,我看到了三种可能的测试方式:
- 制作自定义放置资源class并注册。
- 使用Java空转方法,如
Thread.sleep(240000);
- 写下所有你想要的自动化测试,运行它们。最后做
选定的手动测试。
编辑:根据你的问题,最好的办法是使用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
*/
}
Notice: The most important here is to declare AndroidJUnitRunner
as your Espresso test runner, as we're gonna to use JUnit4
in our
test configuration
最后像这样更改测试 class 代码:
@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)
会让你的测试 classes 一步一步地执行,所以假设在你的第 8 次测试 class 之后你会把
@Test
public void waitUntilManualTestWoulBeDone() {
Thread.sleep(1440000); //sleeps 4 minutes
}
应该可以。
我没有考虑周全,但是创建自己的 ViewAction 可能会停止测试,如下所示:
onView(withText(R.string.some_text)).perform(wait(3 * 60));
我正在为 android 应用程序编写 Espresso 自动化测试,该应用程序通过 NFC 标签与仪器交互。在 NFC 读取和与仪器的手动交互期间,我想将浓缩咖啡测试暂停 3-4 分钟。我们可以在浓缩咖啡测试期间同时进行自动和手动交互吗?是否可以选择闲置资源,因为在暂停期间会有 UI 变化?
好吧,我不明白同时进行自动化和手动测试,理论上自动化测试应该加快检查用户与应用程序交互的过程,并减轻手动测试人员的一些工作。
在 运行 自动 Espresso 测试中间进行手动测试确实是个坏主意。中断测试或更改应用程序状态非常容易,这会导致测试失败。
上次 Google 宣布了 2015 年测试自动化大会 Barista - Espresso 测试的记录器。
在 Espresso 中,我看到了三种可能的测试方式:
- 制作自定义放置资源class并注册。
- 使用Java空转方法,如
Thread.sleep(240000);
- 写下所有你想要的自动化测试,运行它们。最后做 选定的手动测试。
编辑:根据你的问题,最好的办法是使用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
*/
}
Notice: The most important here is to declare
AndroidJUnitRunner
as your Espresso test runner, as we're gonna to useJUnit4
in our test configuration
最后像这样更改测试 class 代码:
@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)
会让你的测试 classes 一步一步地执行,所以假设在你的第 8 次测试 class 之后你会把
@Test
public void waitUntilManualTestWoulBeDone() {
Thread.sleep(1440000); //sleeps 4 minutes
}
应该可以。
我没有考虑周全,但是创建自己的 ViewAction 可能会停止测试,如下所示:
onView(withText(R.string.some_text)).perform(wait(3 * 60));