結論
am instrument に渡した試験 APK の名前が、端末に入っているものと違っていました。adb shell pm list instrumentation で実際の名前を調べ、それを指定したら流れました。
試験の一式を流したら1件だけ落ちたので、揺らぎかどうかを見るために、その1件だけを am instrument で3回流そうとしたときの話です。
症状
試験クラスのパッケージ名(...productuiverification)に .test を付けた名前を、試験 APK の名前として渡しました。
adb shell am instrument -w -r \
-e class <試験クラスのパッケージ>.ProductUiStage78Test#<試験名> \
<試験クラスのパッケージ>.test/androidx.test.runner.AndroidJUnitRunner
3回とも、試験が始まる前に次のエラーで止まりました。
onError: commandError=true message=INSTRUMENTATION_FAILED: <試験クラスのパッケージ>.test/androidx.test.runner.AndroidJUnitRunner
android.util.AndroidException: INSTRUMENTATION_FAILED: <試験クラスのパッケージ>.test/androidx.test.runner.AndroidJUnitRunner
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{<試験クラスのパッケージ>.test/androidx.test.runner.AndroidJUnitRunner}
環境
| 項目 | 値 |
|---|---|
| 端末 | Android エミュレーター(AVD、Android 17) |
| 試験 | AndroidJUnitRunner の計装試験(androidTest) |
| 呼び出し元 | Windows の Git Bash から adb |
原因
am instrument の最後の引数は「端末に入っている試験 APK のパッケージ名/ランナー」です。試験クラスのパッケージ名とは別物です。
今回の試験クラスは productuiverification というパッケージにありましたが、それを含む試験 APK は uiverification.test という名前で入っていました。クラスのパッケージ名から APK の名前を推測したので、存在しない名前を指定していました。
解決手順
- 端末に入っている試験 APK を一覧で見る。
bash
adb shell pm list instrumentation
今回の結果はこうでした(<app> は伏せています)。
instrumentation:<app>.dataverification.test/androidx.test.runner.AndroidJUnitRunner (target=<app>.dataverification)
instrumentation:<app>.loginmigrationverification.test/androidx.test.runner.AndroidJUnitRunner (target=<app>.loginmigrationverification)
instrumentation:<app>.uiverification.test/androidx.test.runner.AndroidJUnitRunner (target=<app>.uiverification)
productuiverification.test はありません。画面の試験クラスが入っているのは uiverification.test です。
-e classは試験クラスの完全な名前のまま、最後の引数だけを一覧にある名前に替える。
bash
adb shell am instrument -w -r \
-e class <試験クラスのパッケージ>.ProductUiStage78Test#<試験名> \
<app>.uiverification.test/androidx.test.runner.AndroidJUnitRunner
- 繰り返し流して揺らぎを見るなら、ループで回す。
bash
for i in 1 2 3; do
adb shell am instrument -w -r -e class <クラス>#<試験名> <app>.uiverification.test/androidx.test.runner.AndroidJUnitRunner \
| grep -a "^OK\|FAILURES\|INSTRUMENTATION_FAILED" | head -3
echo "-- run $i"
done
今回は3回とも OK (1 test) でした。
再発防止・気づき
-e classに書くのは試験クラスの名前、最後の引数に書くのは試験 APK の名前です。モジュールの名前やクラスのパッケージ名から APK の名前を当てずに、pm list instrumentationで見てから書きます。- 1つのモジュールの試験クラスが、別の名前の試験 APK に入っていることがあります。
(target=...)を見ると、どのアプリを相手にする試験かも分かります。 - grep で絞るときは
INSTRUMENTATION_FAILEDも拾うようにしておくと、試験が始まらなかったことを「何も出ない」と見誤らずに済みます。
関連
- Android エミュレーターで「System UI isn’t responding」が前面に出て試験が始まらない:エミュレーターで計装試験が始まらないとき
- Android エミュレーターで「Pixel Launcher isn’t responding」が Wait を押しても消えない:試験の前にランチャーの応答なしが残るとき