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