Android Unit and Instrumentation Test tutorial

Source: Internet
Author: User

Why Android? Is testing for OID applications important?

Android device memory, CPU and battery are limited. The behavior of the application is also related to external factors, such as connectivity, system utilization and so on. So it's important to debug, test, and optimize Android apps.

Android testing is unlikely to cover all Android devices, typically only typical devices. Make sure that your app covers at least the lowest possible configuration devices used and as high as possible to configure devices, such as pixel density, screen resolution, and so on.

The 2015 Android app's support for tools and frameworks has been greatly improved. The Android test system has been updated to JUNIT4-based, and you can run unit tests on a Java virtual machine or at run time on Android. In addition, Google launched a user interface testing framework called espresso.

Android Automated Testing

Test content for Android apps should generally focus on testing the application's business logic. Suggestions:

    • 70-80% unit tests to ensure the stability of your code
    • 20-30% functional testing to ensure that applications work
    • Need to consider cross-application testing in case of interaction

Android Unit and Instrumentation Unit test

The unit tests for Android are based on JUnit. Can be divided into:

    • Local unit Testing-you can run tests on the JVM (fast, priority).
    • Instrumented unit test-requires Android system

Android's Gradle plugin supports Android on the JVM. OID Unit Test. It uses a special version of Android.jar (also known as the Android mockable jar) to support unit testing so that all fields, methods, and classes are available. Any call to the Android mockable jar by default is an exception. Fast but not able to test Android-related content. Instrumented can test the Android API.

Engineering Structure and test folders

Suggestions:

App/src/main/java-Source code

App/src/test/java-Local testing

app/src/androidtest/java-instrumented Unit Test

If you do these conventions, Android build systems will automatically run unit tests on the JVM and run Android tests on Android devices.

Perform tests

Specify the test type:

To view Test execution:

If you see "Error duplicate files in path." Path in Archive:LICENSE.txt "error, modifying App/gradle.build

Android {    packagingoptions {    'LICENSE.txt'    

JVM Unit Test

Reference: http://www.sunmoonblog.com/blog/2015/06/10/android-testing/

Android Unit and Instrumentation Test tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.