Youtube上面关于Espresso单独出了三期的内容讲解Espresso作为整合Unit Test, Instrument Test,end-to-end test等。我试了一下,感觉还不错。
官网地址:
https://google.github.io/android-testing-support-library/docs/index.html
GitHub:
https://github.com/googlesamples/android-testing/tree/master/ui/espresso
我在一个已有的项目里面加入测试用例代码
1. 引入依赖包(使用2.2.2会需要23.1.1,这边会有ERROR曝出, 故降未2.2.1)
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:rules:0.4.1'
2. 设置编译配置
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3.针对登录页面的测试,三个测试case,测试用户名不能为空,测试密码不能为空和输入用户名和密码测试正确性
/**
* 登录测试
*/
@RunWith(AndroidJUnit4.class)
@LargeTest
public class LoginFragmentText {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<MainActivity>(MainActivity.class);
private MainActivity mainActivity;
//这里进入以后 有一个主Fragment, 下面是4个按钮,点击其中一个进入登录页面
@Before
public void switchToLogin () {
LogUtils.debug("switchToLogin...");
onView(withId(R.id.btnProfileID)).perform(click());
mainActivity = mActivityRule.getActivity();
}
//提示都是Toast弹窗提示(下同)
@Test
public void testUsernameNotEmpty() {
onView(withId(R.id.login_login_btn)).perform(click());
onView(withText("用户名不能为空")).inRoot(withDecorView(not(mainActivity.getWindow().getDecorView()))).check(matches(isDisplayed()));
}
@Test
public void testPasswordNotEmpty() {
//注入用户名
onView(withId(R.id.login_username)).perform(click(), clearText(), typeText("1234567"), closeSoftKeyboard());
//点击登录按钮
onView(withId(R.id.login_login_btn)).perform(click());
//弹窗提示
onView(withText("密码不能为空")).inRoot(withDecorView(not(mainActivity.getWindow().getDecorView()))).check(matches(isDisplayed()));
}
@Test
public void testLogin () {
//注入用户名
onView(withId(R.id.login_username)).perform(typeText("1234567"), closeSoftKeyboard());
//注入密码
onView(withId(R.id.login_password)).perform(typeText("123456"), closeSoftKeyboard());
//点击登录按钮
onView(withId(R.id.login_login_btn)).perform(click());
//弹窗提示 登录成功
onView(withText("登录成功")).inRoot(withDecorView(not(mainActivity.getWindow().getDecorView()))).check(matches(isDisplayed()));
}
}
测试的时候,尤其是EditText输入框容易受到手机安装的输入法的影响,可能会出现输入不进入的情况, 这个时候可以用Thread.sleep(XXXX)来暂停捕获画面,比以前的Selenium好用多了
分享到:
相关推荐
Android Espresso UI测试 http://blog.csdn.net/MAIMIHO/article/details/54604318 源码
使用Espresso进行UI测试原文链接 : Using Espresso for Easy UI Testing原文作者 : Michael Evans译者
使用espresso插件,可以在Flutter应用程序中编写自动化测试用例,对应用程序的界面进行测试和验证。与Flutter的其他测试框架相比,espresso插件提供了更丰富的界面测试功能,例如可以模拟用户点击、滑动等操作,并对...
使用Espresso测试UI
Espresso Shack
Espresso 使用Espresso测试AppUI
Espresso测试框架的jar包,包含所有api文档
Espresso Espresso是基于深度学习库PyTorch和流行的神经机器翻译工具Fairseq的开源,模块化,可扩展的端到端神经自动语音识别(ASR)工具包。Espres Espresso Espresso是基于深度学习库PyTorch和流行的神经机器翻译...
浓咖啡+Cucumber+汤匙使用Espresso测试框架和CucumberBDD语言和Spoon屏幕截图测试Android应用程序的库。 该库的目的是使用户界面测试能够通过JUnit访问应用程序内部,同时以自然英语表示,并在需要时提供屏幕截图...
一个kotlin库,以简化如何在Android上进行espresso测试
Espresso 是一套简洁、美观且可靠的 Android 界面测试库。核心 API 小巧、可预测且易于学习,但仍可进行自定义。Espresso 测试会清楚地说明预期、交互和断言,让您不受样板内容、自定义基础架构或杂乱的实现细节干扰...
极其强大的编辑,圆滑的项目,实时预览,真正的部分和广泛的同步工具功能,还有惊人的可扩展能力,Espresso支持code folding,还能以dom方式呈现,另外Espresso支持外挂,也就是说可以自己建立需要的语法,还支持正则...
MediaShow.Espresso.v5.0破解片
Android Espresso for writing Automated UI Tests. 2019.
Android Espresso Samples A collection of samples demonstrating different Espresso techniques.
quantum espresso开发团队的大作,详细讲解,不容错过!
Espresso是基于深度学习库和流行的神经机器翻译工具的开源,模块化,可扩展的端到端神经自动语音识别(ASR)工具包。 Espresso支持在GPU和计算节点之间进行分布式训练,并具有ASR中常用的各种解码方法,包括基于超前...
对于基于UI的功能测试的需求其实一直存在,理由其实很简单,不想一直让人去做重复机械的事情,而且可靠性完全是靠人力的堆积产生。然而现在行业大多数公司的功能测试工作依然主要是依靠人工来完成,从我们公司的实践...
Quantum espresso是一个开源的DFT计算模拟软件,本资源是其7.0.1版在Archlinux和Manjaro Linux上的安装包。 本安装包需要openmpi,Cuda,gcc,gfortran,lapack和scalapack支持。
Quantum Espresso is an integrated suite of Open-Source computer codes for electronic-structure calculations and materials modeling at the nanoscale. It is based on density-functional theory, plane ...