robotium的一个缺点就是不能跨应用,但是现在的应用几乎都会有分享的功能,要不就是第三方登录;还有就是拍照这种调用本机相机功能,那肯定会有跨应用的时候,那怎么解决呢。uiautomator就是可以跨应用的,两个结合起来就可以啦。
借助http请求来作为robotium和uiautomator的通信工具,android项目,我们使用okHttp
1.先用robotium写了要测试的操作流程,用uiautomator编写在其他应用中的操作流程。
2.使用eclipse(EE版本)编写server项目
3.在android studio的robotium项目中编写okHttp类
4.pc连接手机,且pc和手机连接同一网络
5.运行robotium测试代码,等待结果
server项目
eclipse mars版本新建web项目
new -> others -> Web -> Dynamic Web Project

tomate8.0版本有个8.5的版本,但是在这里不能使用,只能选用8.0版本的。如果这里的runtime没有tomcat 8.0可以选择,下载eclipse mars版本就有了



添加servlet-api.jar(引用tomcat-lib中的servlet-api.jar)

新建servlet

输入package &Class name

直接finish。java文件中自动创建类

加入json类

导入本地json.jar1

导入本地json.jar2

编写doGet

运行是否正确:run as--->run on server


打开浏览器,url输入ip:端口/Project/className

uiautomator代码
编写跨进程的代码

android studio中robotium项目
添加okhttp依赖。在build.gradle(Module)中添加

视图切换到Project,在app->proguard-rules.pro中添加对okHttp提示的忽视

通信的代码(使用OkHttpClient)。写法参照okHttp官网给出的示例

编写交互的测试代码

运行测试代码即可
网友评论