Android Test (iii): Android unit Test

Source: Internet
Author: User

Android Test (iii): Android unit Test

Release date December 20, 2017 bug Master

Original: https://developer.android.com/training/testing/unit-testing/index.html

Unit testing is a basic test of your application's test strategy. By creating and running unit Tests against your code, you can easily verify that the logic of each unit is correct. Running unit tests after each build can help you quickly capture and fix software regressions introduced by code changes to your application.

Unit tests typically implement the functionality of the smallest possible unit of code (which can be a method, a class, or a component) in a repeatable manner. When you need to validate the logic of specific code in your application, you should build unit tests. For example, you create a class in which unit tests can help check if the class is in the correct state. Typically, unit tests are relatively independent, and your tests only affect and check the changes to the unit being tested, and the mock framework can be used to isolate the dependencies you want to test the unit.

Note: Unit tests are not suitable for testing complex UI interaction events. Instead, you should use the UI test framework, as described in UI Automation testing.

In order to test Android apps, you typically need to create these types of unit tests:

    • Local test: Unit tests that run only on the local machine. These tests are compiled to run locally on the Java Virtual Machine (JVM) to minimize execution time. Use this method to run unit tests that do not rely on the Android framework, or you can use mock objects to populate dependencies.

    • Instrumented test: Unit tests that run on an Android device or emulator. These tests can access tool information, such as the context of the application being tested. Use this method to run unit tests that have Android dependencies that cannot be easily populated with mock objects.

The next step is to show you how to build these two types of unit tests.

The lessons in this lesson will show you how to build these types of automated unit tests.

Lessons

Building Local unit Tests (creation of native units test)

Learn how to build unit tests that run on your local machine.

Building instrumented Unit Tests (create instrumented unit test)

Learn how to build unit tests that run on an Android device or emulator.

Android Test (iii): Android unit Test

Related Article

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.