1# Instrumentation Tests 2 31. Below are common destinations for hermetic tests against framework services: 4 5 ``` 6 frameworks/base/core/tests/coretests 7 frameworks/base/services/tests/servicestests 8 ``` 9 10 If you are adding a brand new instrumentation module for your component, see 11 12 * [Self-Instrumenting Tests: A Complete Example](instr-self-e2e.md) 13 * [Instrumentation Targeting an Application: A Complete Example] 14 (instr-app-e2e.md) 15 161. Following the existing convention if you are adding tests into one of the 17 locations above. If you are setting up a new test module, please follow the 18 setup of `AndroidManifest.xml` and `Android.mk` in one of the locations 19 above 20 211. See https://android.googlesource.com/platform/frameworks/base.git/+/master/core/tests/coretests/ for an example 22 231. Note: do not forget to mark your test as `@SmallTest`, `@MediumTest` or 24 `@LargeTest` 25 261. Build the test module with make, e.g.: 27 28 ``` 29 make FrameworksCoreTests -j 30 ``` 31 321. Automatic installation and run with the TradeFederation test harness: 33 34 ``` 35 make tradefed-all -j 36 tradefed.sh run template/local_min --template:map test=FrameworksCoreTests 37 ``` 38 391. Manually Install and Run: 40 1. Install the generated apk: 41 42 ``` 43 adb install -r ${OUT}/data/app/FrameworksCoreTests/FrameworksCoreTests.apk 44 ``` 45 46 Tip: you use `adb shell pm list instrumentation` to find the 47 instrumentations inside the apk just installed 48 49 1. Run the tests with various options: 50 51 1. all tests in the apk 52 53 ``` 54 adb shell am instrument -w com.android.frameworks.coretests\ 55 /android.support.test.runner.AndroidJUnitRunner 56 ``` 57 58 1. all tests under a specific Java package 59 60 ``` 61 adb shell am instrument -w -e package android.animation \ 62 com.android.frameworks.coretests\ 63 /android.support.test.runner.AndroidJUnitRunner 64 ``` 65 66 1. all tests under a specific class 67 68 ``` 69 adb shell am instrument -w -e class \ 70 android.animation.AnimatorSetEventsTest \ 71 com.android.frameworks.coretests\ 72 /android.support.test.runner.AndroidJUnitRunner 73 ``` 74 75 1. a specific test method 76 77 ``` 78 adb shell am instrument -w -e class \ 79 android.animation.AnimatorSetEventsTest#testCancel \ 80 com.android.frameworks.coretests\ 81 /android.support.test.runner.AndroidJUnitRunner 82 ``` 83 84Your test can make an explicit assertion on pass or fail using `JUnit` APIs; in 85addition, any uncaught exceptions will also cause a functional failure. 86 87To emit performance metrics, your test code can call 88[`Instrumentation#sendStatus`](http://developer.android.com/reference/android/app/Instrumentation.html#sendStatus\(int, android.os.Bundle\)) 89to send out a list of key-value pairs. It's important to note that: 90 911. metrics can be integer or floating point 921. any non-numerical values will be discarded 931. your test apk can be either functional tests or metrics tests, however 94 mixing both are not currently supported 95