Skip to content

Instantly share code, notes, and snippets.

@MasayukiFukada
Created February 6, 2018 14:40
Show Gist options
  • Save MasayukiFukada/337936b976abef6de218dfbc1d01a005 to your computer and use it in GitHub Desktop.
Save MasayukiFukada/337936b976abef6de218dfbc1d01a005 to your computer and use it in GitHub Desktop.
Android command line test for CI.CI用のコマンド

Android でコマンドラインからテストをしたい向きのためのメモ

executeTest.sh

  • emulator コマンドが重要
    • フルパスじゃないとコマンドが動かなかったので、whereisを利用
    • バックグラウンドで動かす必要あり
    • 起動まで時間が掛かるなら少し待つ必要がありそう
  • テストが終わったらエミュは片付けておく
#!/bin/bash
emu=`whereis emulator | gawk '{print $2}'`
$emu -avd CoverageTest &
./gradlew createDebugCoverageReport
emu_process=`ps -ax | grep CoverageTest | grep avd | gawk '{print $1}'`
kill $emu_process

coverage.sh

  • xmllint コマンドが入っていること
  • 割と強引に算出してる(C2カバレッジ = Branch)
#!/bin/bash
values=`xmllint --xpath 'report/counter[@type="BRANCH"]' ./app/build/reports/coverage/debug/report.xml | sed -e 's/.*missed="\([0-9]\+\)".*covered="\([0-9]\+\)".*/\1 \2/'`
echo $values | gawk -e '{printf("Coverage:%0.2f%\n",$2*100/($1+$2))}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment