1+ /*
2+ * run from dir: test-app/
3+ * run on emulator: ./gradlew :app:runtest //default
4+ * run on device: ./gradlew :app:runtest -PrunOnDevice
5+ *
6+ */
7+
8+
19def isWinOs = System . properties[' os.name' ]. toLowerCase(). contains(' windows' )
210
311apply plugin : ' com.android.model.application'
412
13+ def runOnDevice = project. hasProperty(" runOnDevice" );
14+ def runOnDeviceOrEmulator = runOnDevice ? " -d" : " -e" ;
15+
516model {
617 android {
718 compileSdkVersion = 23
@@ -49,12 +60,12 @@ task deleteDist (type: Delete) {
4960task installApk (type : Exec ) {
5061 doFirst {
5162 println " Attempting to install buit apk"
52-
63+
5364 if (isWinOs) {
54- commandLine " cmd" , " /c" , " node" , " $rootDir \\ tools\\ deploy-apk.js" , " $rootDir \\ app\\ build\\ outputs\\ apk\\ app-debug.apk"
65+ commandLine " cmd" , " /c" , " node" , " $rootDir \\ tools\\ deploy-apk.js" , " $rootDir \\ app\\ build\\ outputs\\ apk\\ app-debug.apk" , runOnDeviceOrEmulator
5566 }
5667 else {
57- commandLine " node" , " $rootDir /tools/deploy-apk.js" , " $rootDir /app/build/outputs/apk/app-debug.apk"
68+ commandLine " node" , " $rootDir /tools/deploy-apk.js" , " $rootDir /app/build/outputs/apk/app-debug.apk" , runOnDeviceOrEmulator
5869 }
5970 }
6071
@@ -66,12 +77,12 @@ task installApk (type: Exec) {
6677task deletePreviousResultXml (type : Exec ) {
6778 doFirst {
6879 println " Removing previous android_unit_test_results.xml"
69-
80+
7081 if (isWinOs) {
71- commandLine " cmd" , " /c" , " adb" , " shell" , " rm" , " -rf" , " /sdcard/android_unit_test_results.xml"
82+ commandLine " cmd" , " /c" , " adb" , runOnDeviceOrEmulator , " shell" , " rm" , " -rf" , " /sdcard/android_unit_test_results.xml"
7283 }
7384 else {
74- commandLine " adb" , " shell" , " rm" , " -rf" , " /sdcard/android_unit_test_results.xml"
85+ commandLine " adb" , runOnDeviceOrEmulator, " shell" , " rm" , " -rf" , " /sdcard/android_unit_test_results.xml"
7586 }
7687 }
7788}
@@ -81,10 +92,10 @@ task startInstalledApk (type: Exec) {
8192 println " Starting test application"
8293
8394 if (isWinOs) {
84- commandLine " cmd" , " /c" , " adb" , " shell" , " am" , " start" , " -n" , " com.tns.android_runtime_testapp/com.tns.NativeScriptActivity" , " -a" , " android.intent.action.MAIN" , " -c" , " android.intent.category.LAUNCHER"
95+ commandLine " cmd" , " /c" , " adb" , runOnDeviceOrEmulator, " shell" , " am" , " start" , " -n" , " com.tns.android_runtime_testapp/com.tns.NativeScriptActivity" , " -a" , " android.intent.action.MAIN" , " -c" , " android.intent.category.LAUNCHER"
8596 }
8697 else {
87- commandLine " adb" , " shell" , " am" , " start" , " -n" , " com.tns.android_runtime_testapp/com.tns.NativeScriptActivity" , " -a" , " android.intent.action.MAIN" , " -c" , " android.intent.category.LAUNCHER"
98+ commandLine " adb" , runOnDeviceOrEmulator, " shell" , " am" , " start" , " -n" , " com.tns.android_runtime_testapp/com.tns.NativeScriptActivity" , " -a" , " android.intent.action.MAIN" , " -c" , " android.intent.category.LAUNCHER"
8899 }
89100 }
90101}
@@ -101,10 +112,10 @@ task waitForUnitTestResultFile (type: Exec) {
101112 println " Waiting for tests to finish..."
102113
103114 if (isWinOs) {
104- commandLine " cmd" , " /c" , " node" , " $rootDir \\ tools\\ try_to_find_test_result_file.js"
115+ commandLine " cmd" , " /c" , " node" , " $rootDir \\ tools\\ try_to_find_test_result_file.js" , runOnDeviceOrEmulator
105116 }
106117 else {
107- commandLine " node" , " $rootDir /tools/try_to_find_test_result_file.js"
118+ commandLine " node" , " $rootDir /tools/try_to_find_test_result_file.js" , runOnDeviceOrEmulator
108119 }
109120 }
110121}
0 commit comments