Reference Document: Https://developer.android.com/training/testing/start/index.html
Test classification
To test with Android studio, you first need to understand the classification of Android tests, and after you create a new project, the project will default to two test catalogs:
1. Local unit Test (tests)
The test code is locatedmodule-name/src/test/java/,这些测试直接运行在本地JVM上,不需要使用Android框架的API。
2, Equipment testing (instrumented tests)
The test code is located in located atmodule-name/src/androidTest/java/,这些测试代码必须运行在Android设备或者Android虚拟机上。
The instrumented test code is packaged into an apk and then runs on the phone. Because running on the device, you can use some of the methods inside the app, modify some properties, and automate the simulation of user interaction.
The above two classifications are based on whether the test runs on the local JVM or is run on the Android platform. A complete set of tests are categorized as follows:
Type |
Sub-type |
Describe |
Unit Test |
Native Unit Testing (local units Tests) |
A unit test that runs on the local JVM. You can use this test to reduce test execution time when the code being tested does not depend on the Android framework API, or when simulating androidapi. |
|
Device Unit Test (instrumented unit tests) |
Unit tests that run on Android devices or emulators. These tests run with the need for device information, such as the context of the app. |
Integration Testing |
App Component Testing |
This type of test is to verify that the app responds as expected when the user makes certain actions on the activity or enters certain values. |
|
Cross-app component testing |
This type of test is intended to verify the correct behavior when interacting between the user app and the system app. |
Test API
Here are some of the generic Test APIs that are introduced on Android
1. JUnit
2. Android Testing Support Library (Androidjunitrunner,espresso,ui Automator)
3, assertion classes (Hamcrest library)
4, Monkey and Mokeyrunner
You will then describe how to use it separately.
Android test: Start from scratch introduction