Android Junit Test(semc-build编译并且生成emma coverage)
任昊阳
2023-12-01
========================================================
get emma coverage steps:
========================================================
1. build target app and test app:
semc-build debug-test-instr -Demma-coverage-on=true -Drun-emma=true
解决自动重启并且清除data:semc-build ci-onrunning-instr -Demma-coverage-on=true -Drun-emma=true
2. adb push target app into phone
adb push SomcChameleonWorkflow /system/priv-app/
adb push bin/SomcChameleonWorkflow.apk /system/priv-app/SomcChameleonWorkflow/
adb push semc-build-output/SomcChameleonWorkflow/bin/SomcChameleonWorkflow.apk /system/priv-app/SomcChameleonWorkflow/
3. install test app into phone
adb install -r semc-build-output/test-SomcChameleonWorkflow/bin/test-SomcChameleonWorkflow.apk
4. run auto test(-r -e coverage true -e 生成coverage.ec文件)
adb shell am instrument -r -e coverage true -e class com.sonymobile.chameleon.workflow.FBasicSetupActivity -w com.sonymobile.chameleon.workflow.tests/android.test.InstrumentationTestRunner
adb shell am instrument -r -e coverage true -e class com.sonymobile.chameleon.workflow.FBasicSetupActivity -w com.sonymobile.chameleon.workflow.tests/com.sonymobile.chameleon.workflow.runners.FunctionalTestRunner
adb shell am instrument -r -e coverage true -e class com.sonymobile.chameleon.workflow.FBasicSetupActivity -w com.sonymobile.chameleon.workflow.tests/com.sonymobile.chameleon.workflow.runners.UnitTestRunner
5. pull out the .ec file from the phone
adb pull /data/data/com.sonymobile.chameleon.workflow/files/coverage.ec reports/coverage/
6. generate emma coverage report:
java -Xmx128m -cp ~/.semctools/emma/emma.jar emma report -r html -sp ./src -in reports/coverage/coverage.ec,reports/coverage/coverage.em
Notes:
1. 以上每一步都是在workflow的代码根目录:vendor/semc/packages/apps/chameleon/workflow$
2. 手机需要烧ivy-aya的Eng版本,之前我用user debug版本不行
7.全部test,并且生成报告:
adb shell am instrument -r -e coverage true -w com.sonymobile.chameleon.workflow.tests/android.test.InstrumentationTestRunner
adb pull /data/data/com.sprint.internal.id/files/coverage.ec reports/coverage/
合成报告:
java -Xmx128m -cp ~/.semctools/emma/emma.jar emma report -r html -sp ./src -in reports/coverage/coverage-no-sim.ec,reports/coverage/coverage-sim.ec,reports/coverage/coverage.em
使用命令获取最新label,如:32.x.x.x:
repository latestlabel l-kitakami-softbank
使用命令下载sdk
sdkdownload -l 32.x.x.x
配置sdk环境变量: ANDROIDSDK_HOME
使用命令semc-build编译apk
semc-build ci-onrunning-instr -Demma-coverage-on=true -Drun-emma=true
semc-build debug-test-instr -Demma-coverage-on=true
adb shell am instrument -w com.sonymobile.simplehome.tests/com.sonymobile.simplehome.runners.FunctionalTestRunner
========================================================
auto test code build:
========================================================
semc-build debug-test-instr
========================================================
simple-home2 auto test cmd:
========================================================
semc-build debug-test-instr reinstall-testapk instr -Ddevice-name=CB5A1Y3FAH -DtestRunners="UnitTestRunner FunctionalTestRunner StabilityTestRunner"
========================================================
Ivy-aya:
========================================================
semc-build debug-test-instr reinstall-testapk instr -Ddevice-name=CB5A23PXHQ -DtestRunners="FunctionalTestRunner"
========================================================
All test cases
========================================================
adb shell am instrument -r -w com.sonymobile.chameleon.workflow.tests/android.test.InstrumentationTestRunner
adb shell am instrument -r -w com.sonymobile.chameleon.workflow.tests/com.sonymobile.chameleon.workflow.runners.FunctionalTestRunner
adb shell am instrument -r -w com.sonymobile.chameleon.workflow.tests/com.sonymobile.chameleon.workflow.runners.UnitTestRunner
========================================================
ChameleonReceiver:
========================================================
adb shell am instrument -r -e class com.sonymobile.chameleon.workflow.UChameleonReceiver#testOnReceive -w com.sonymobile.chameleon.workflow.tests/com.sonymobile.chameleon.workflow.runners.UnitTestRunner
========================================================
ChameleonSimLockService
========================================================
adb shell am instrument -r -e class com.sonymobile.chameleon.workflow.UChameleonSimLockService -w com.sonymobile.chameleon.workflow.tests/com.sonymobile.chameleon.workflow.runners.UnitTestRunner
========================================================
RtnReceiver:
========================================================
adb shell am instrument -r -e class com.sonymobile.chameleon.workflow.URtnReceiver#testOnReceive -w com.sonymobile.chameleon.workflow.tests/com.sonymobile.chameleon.workflow.runners.UnitTestRunner
========================================================
BasicSetupActivity:
========================================================
adb shell am instrument -r -e class com.sonymobile.chameleon.workflow.FBasicSetupActivity#testBasicSetupActivity -w com.sonymobile.chameleon.workflow.tests/android.test.InstrumentationTestRunner
========================================================
ChameleonEntryActivityTest:
========================================================
adb shell am instrument -r -e class com.sonymobile.chameleon.workflow.FChameleonEntryActivity#testChameleonEntryActivity -w com.sonymobile.chameleon.workflow.tests/android.test.InstrumentationTestRunner
========================================================
FHfaFailedActivity:
========================================================
adb shell am instrument -e class com.sonymobile.chameleon.workflow.FHfaFailActivity#testHfaFailed -w com.sonymobile.chameleon.workflow.tests/android.test.InstrumentationTestRunner
========================================================
FMsisdnUpdateActivity:
========================================================
adb shell am instrument -e class com.sonymobile.chameleon.workflow.FMsisdnUpdateActivity#testMsisdnOta -w com.sonymobile.chameleon.workflow.tests/android.test.InstrumentationTestRunner