forked from iSoron/uhabits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests
executable file
·64 lines (51 loc) · 1.98 KB
/
run_tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
PACKAGE_NAME=org.isoron.uhabits
OUTPUT_DIR=app/build/outputs
LOG=${OUTPUT_DIR}/test.log
info() {
local COLOR='\033[1;32m'
local NC='\033[0m'
echo -e " $COLOR*$NC $1"
}
fail() {
cat $LOG
exit 1
}
info "Cleaning output directory..."
rm -rf ${OUTPUT_DIR}
mkdir -p ${OUTPUT_DIR}
info "Running JVM tests..."
./gradlew :app:testDebugUnitTest >> $LOG 2>> $LOG || fail
info "Building instrumentation APKs..."
./gradlew assembleDebug assembleAndroidTest >> $LOG 2>> $LOG || fail
info "Installing APK..."
adb install -r ${OUTPUT_DIR}/apk/app-debug.apk >> $LOG 2>> $LOG || fail
adb install -r ${OUTPUT_DIR}/apk/app-debug-androidTest-unaligned.apk \
>> $LOG 2>> $LOG || fail
info "Granting permissions..."
adb shell pm grant org.isoron.uhabits android.permission.SET_ANIMATION_SCALE \
>> $LOG 2>> $LOG || fail
info "Running instrumentation tests..."
adb shell am instrument \
-e coverage true -e size medium \
-w ${PACKAGE_NAME}.test/android.support.test.runner.AndroidJUnitRunner \
| tee ${OUTPUT_DIR}/runner.txt \
| tee -a $LOG
grep -q "Error" ${OUTPUT_DIR}/runner.txt && failed=1
info "Fetching failed generated files..."
mkdir -p ${OUTPUT_DIR}/failed
adb pull /mnt/sdcard/test-screenshots/ ${OUTPUT_DIR}/failed >> $LOG 2>> $LOG
adb pull /storage/sdcard/test-screenshots/ ${OUTPUT_DIR}/failed >> $LOG 2>> $LOG
adb pull /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ ${OUTPUT_DIR}/failed >> $LOG 2>> $LOG
adb shell rm -r /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ >> $LOG 2>> $LOG
info "Fetching logcat..."
adb logcat -d > ${OUTPUT_DIR}/logcat.txt
info "Building coverage report..."
mkdir -p ${OUTPUT_DIR}/code-coverage/connected/
adb pull /data/data/${PACKAGE_NAME}/files/coverage.ec \
${OUTPUT_DIR}/code-coverage/connected/ >> $LOG 2>> $LOG
./gradlew app:createDebugCoverageReport \
-x app:connectedDebugAndroidTest >> $LOG 2>> $LOG
info "Uninstalling test APK..."
adb uninstall ${PACKAGE_NAME}.test >> $LOG 2>> $LOG
exit $failed