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