Expert: Integration Cloud Testing in Jetpack Android App Part-2

Manoj Kumar
5 min readDec 10, 2021

--

Overview

In this article, I will create an Android Jetpack based Recipe App in which I will integrate HMS Core kits such as Huawei ID, Huawei Ads and Cloud Testing.

In this series of article I will cover all the kits with real life usages in this application. This is the part-2 article of this series.

Part 1 : https://forums.developer.huawei.com/forumPortal/en/topic/0202739009635070571?fid=0101187876626530001

Huawei Cloud Testing

Cloud Testing provides a complete set of automatic test processes based on real mobile phone use. It tests automatically the compatibility, stability, performance, and power consumption of Android apps, without manual intervention.

Prerequisite

1. A computer (desktop or laptop)

2. A Huawei phone, which is used to debug the developed app

3. HUAWEI Analytics Kit 5.0.3.

4. Android SDK applicable to devices using Android API-Level 19 (Android 4.4 KitKat) or higher.

5. Android Studio

6. Java JDK 1.7 or later (JDK 1.8 recommended)

App Gallery Integration process

Sign In and Create or Choose a project on AppGallery Connect portal.

Navigate to Project settings > download the configuration file.

​​​​​​​

Navigate to General Information > Data Storage location.

​​​​​​​

Navigate to Project Setting > Quality > Cloud Testing.

​​​​​​​

Compatibility Test

The compatibility test of Cloud Test allows you to perform real machine tests. The test automatically verifies 11 compatibility issues, including the app installation, start up, crash, application not responding (ANR), unexpected exit, running error, UI error, black/white screen, exit failure, account exception, and uninstallation.

Creating a Compatibility Test Task

  1. Choose Compatibility test.
  2. Create New Test, choose Compatibility test tab, then upload the APK package of the app and select the app after the upload is complete.
  3. Click Next. The page for selecting test phones is displayed.
  4. Click OK. In the displayed Information dialog box, you can click Create another test to create another test task or click View test list to go to the test result page.

​​​​​​​

Stability Test

In a stability test, long-term traverse testing and random testing are performed to detect app stability issues such as the memory leakage, memory overwriting, screen freezing, and crash on Huawei phones.

Choose Stability test.

  1. Create New Test, choose stability test tab then upload the APK package of the app and select the app after the upload is complete.
  2. Click Next. The page for selecting test phones is displayed.
  3. Click OK. In the displayed Information dialog box, you can click Create another test to create another test task or click View test list to go to the test result page.

​​​​

Performance Test

The performance test in Cloud Test collects performance data on real phones and analyzes app performance defects in depth. This test supports analysis of the startup duration, frame rate, memory usage, and app behaviors.

  1. Create New Test, choose Performance test tab then upload the APK package of the app or Select existing app and select the app after the upload is complete.
  2. Click Next. The page for selecting test phones is displayed.
  3. Click OK. In the displayed Information dialog box, you can click Create another test to create another test task or click View test list to go to the test result page.

​​​​​

Power Consumption

In the power consumption test of Cloud Test, you can check key indicators and determine how your app affects the power consumption of devices.

  1. Create New Test, choose Power Consumption test tab then upload the APK package of the app or Select existing app and select the app after the upload is complete.
  2. Click Next. The page for selecting test phones is displayed.
  3. Click OK. In the displayed Information dialog box, you can click Create another test to create another test task or click View test list to go to the test result page.

​​​​

App Development

Create A New Project.

Configure Project Gradle.

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {

repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}​​

Configure App Gradle.

//HMS Kits
api 'com.huawei.hms:dynamicability:1.0.11.302'
implementation 'com.huawei.agconnect:agconnect-auth:1.4.1.300'
implementation 'com.huawei.hms:hwid:5.3.0.302'
implementation 'com.huawei.hms:ads-lite:13.4.30.307'
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.6.0.300'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation "com.squareup.retrofit2:converter-gson:2.6.2"
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.2'
implementation "com.squareup.retrofit2:adapter-rxjava2:2.6.2"

Configure AndroidManifest.xml.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Jetpack Components Implementation

  • Data Binding: Declaratively bind UI elements to in our layout to data sources of our app.
  • Lifecycles: Manages activity and fragment lifecycles of our app.
  • LiveData: Notify views of any database changes.
  • Room: Fluent SQLite database access.
  • ViewModel: Manage UI-related data in a lifecycle-conscious way.
  • ViewModel Code:
  • Activity Code:
  • Repository Code:
  • Login and Ads Code:
  • Room Implementation:

App Build Result

Tips and Tricks

  • Only one model can be selected for the stability test at a time.
  • In normal cases, a compatibility or performance test takes about 60 minutes, a power consumption test takes about 100 minutes, and the duration of a stability test is set by you. If the test duration exceeds the preceding duration, you can submit the problem with detailed description.

Conclusion

In this article, we have learned how to integrate Cloud Testing in Android application. After completely read this article user can easily implement Cloud Testing in the android based application.

Thanks for reading this article. Be sure to like and comment to this article, if you found it helpful. It means a lot to me.

References

HMS Docs:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050048870

https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-cloudtest-introduction-0000001083002880

--

--

Manoj Kumar
Manoj Kumar

No responses yet