Instrumented unit testing refers to testing that runs on a physical machine or simulator, so you can use the Android framework's API and the supporting API. This will be the case where you need to use device information, such as app context, you can use the instrumented unit test. Using the instrumented unit test can also reduce the code of the Mock (and, of course, the code to write the mock).
The generic test code is placed below the app/src/androidtest/java/. You need to introduce a dependent library in the Build.gradle configuration before starting the test:
dependencies { androidtestcompile ' com.android.support:support-annotations:24.0.0 ' androidtestcompile ' com.android.support.test:runner:0.5 ' androidtestcompile ' com.android.support.test:rules:0.5 ' //Optional --hamcrest Library androidtestcompile ' org.hamcrest:hamcrest-library:1.3 ' //Optional-UI testing with Espresso androidtestcompile ' com.android.support.test.espresso:espresso-core:2.2.2 ' //Optional--UI Testing with UI Automator androidtestcompile ' com.android.support.test.uiautomator:uiautomator-v18:2.1.2 '}
If the configuration contains both the Support-annotation library and the Espress-core library, the build may fail. You need to add in the configuration:
Androidtestcompile (' com.android.support.test.espresso:espresso-core:2.2.2 ', { exclude group: ' Com.android.support ', module: ' Support-annotations '})
Android Test: zero-based 3--instrumented unit Test 1