Difference between Android Instrumentation test and Unit test in Android Studio?

后端 未结 6 1919
被撕碎了的回忆
被撕碎了的回忆 2020-12-12 11:20

As of Android Studio 1.1rc there\'s Unit testing support and I\'m wondering what\'s the difference between Android Instrumentation Tests and Unit tests.

6条回答
  •  猫巷女王i
    2020-12-12 11:51

    UNIT TESTING

    Unit tests that run on your local machine only. These tests are compiled to run locally on the JVM to minimize execution time. Use this approach to run unit tests that have no dependencies on the Android framework or have dependencies that mock objects can satisfy.

    So basically, you run plain java code to test for example a content provider, database connections, input and output of methods. This doesn't run on Android. To run it you DON'T need a device.

    INSTRUMENTATION TESTING

    Unit tests that run on an Android device or emulator. These tests have access to Instrumentation information, such as the Context of the app under test. Use this approach to run unit tests that have Android dependencies which mock objects cannot easily satisfy.

    So it mocks how the user will use the actual application, therefore you NEED a device (physical or emulator) to run it. It has access to views, activities, context, etc.

    Reference: http://developer.android.com/tools/testing/testing_android.html

提交回复
热议问题