The command to run the toolkit from the adb shell : -
adb shell am instrument -w com.android.vishal.project.test/android.test.InstrumentationTestRunner
Android code to run the toolkit from Android Activity : -
startInstrumentation(new ComponentName("com.android.vishal.project.test", "android.test.InstrumentationTestRunner"), null, null);
Note:
Another method
Android code to run the toolkit (Android 2.3 to Android 4.1.2)
String str_cmd = "adb shell am instrument -w com.android.vishal.project.test/android.test.InstrumentationTestRunner"; Runtime.getRuntime().exec(str_cmd);
Android 4.2 requires the permission "android.permission.INJECT_EVENTS" and is only allowed by the system application. The user application cannot use this permission due to some security reasons.
therefore you cannot use Runtime.getRuntime (). exec (str_cmd); for Android 4.2 onwards ...
so now the working method:
startInstrumentation(new ComponentName("com.android.vishal.project.test", "android.test.InstrumentationTestRunner"), null, null);
run this command from your activity.
Thanks.
source share