学习资料
官方文档
在 Android 平台上测试应用 | Android 开发者 | Android Developers
测试了解
Android单元测试全解_android 单元测试_一代小强的博客-CSDN博客
Android单元测试-对Activity的测试_activitytestrule_许佳佳233的博客-CSDN博客
单元测试注解相关
ActivityScenarioRule懒加载_airgreen的博客-CSDN博客
学习资料可以了解一下,不用进行深入,重点需要的准备在下面。
前置准备
-
按照 Android 项目导入高德 SDK 使用(从小白到入门) 这篇文档,把高德地图 SDK 环境给部署在自己的空项目中,然后能够正常的调用基本高德地图SDK
-
学习SDK这部分看到什么程度,了解即可。不熟悉 可以 照着文档 控件交互-与地图交互-开发指南-Android 地图SDK | 高德地图API 调用SDK接口写几个简单的功能能够正常运行展示即可)
-
了解 Junit 框架的一些注解和断言方法就没问题,不用深入
步骤记录
简单上手 AndroidTest 来测试验证高德地图SDK的接口,简单记录一下操作过程
0、首先我们有一个部署好高德 SDK 环境的项目,能够正常显示一个地图 MapView 。
1、把下列配置代码 贴到模块的 build.gradle 文件里面,在 dependencies 闭包中
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//测试添加
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// implementation 'pub.devrel:easypermissions:2.0.1'
implementation 'com.google.code.gson:gson:2.8.5'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
// androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
2、我们在 AndroidTest 的 test 测试类中默认就能看到有下列代码,之后我们就会在 androidTest 目录下的类中写测试用例代码。
![[图片]](/https://i-blog.csdnimg.cn/blog_migrate/c844f1fc81c82bc39c2235cc26934a46.png)
3、我们在 layout 建一个页面视图activity_exercise.xml,添加一个 mapView 标签即可,在对应的 Java类 ExerciseActivity 显示地图,这里可以设置一个默认显示的地图中心点,方便后面进行测试验证。
public class ExerciseActivity extends AppCompatActivity {
public MapView mapView;
public static final LatLng SHANGHAI = new LatLng(31.238068, 121.501654);
@Override
protected void onCreate(Bundle savedInstanceState) {

本文介绍了如何在Android项目中使用AndroidTest框架对高德地图SDK进行单元测试,包括配置测试依赖、ActivityTestRule的应用以及测试地图功能和UI控件的示例。
&spm=1001.2101.3001.5002&articleId=132175278&d=1&t=3&u=4a07760c0f4c40aab1abfdf9fea08bf6)
2066

被折叠的 条评论
为什么被折叠?



