高德地图 SDK 接口测试接入(AndroidTest 上手)

本文介绍了如何在Android项目中使用AndroidTest框架对高德地图SDK进行单元测试,包括配置测试依赖、ActivityTestRule的应用以及测试地图功能和UI控件的示例。

学习资料


官方文档

在 Android 平台上测试应用 | Android 开发者 | Android Developers

测试了解

【玩转Test】开篇-Android test 介绍

Android单元测试全解_android 单元测试_一代小强的博客-CSDN博客

Android单元测试-对Activity的测试_activitytestrule_许佳佳233的博客-CSDN博客

单元测试注解相关

ActivityScenarioRule懒加载_airgreen的博客-CSDN博客

学习资料可以了解一下,不用进行深入,重点需要的准备在下面。


前置准备


步骤记录


简单上手 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 目录下的类中写测试用例代码。


[图片]


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) {
   
   
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

RAIN 7

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值