簡単なUnitTestとUIテストを実装し(Java:Android)、JaCoCoによってCoverageを表示する為のサンプルです。
- macOS Version: 10.14.6
- Android Studio Version: 4.0
- Android Emulator API Version: 28
- JAVA Version: jdk1.8.0_191 (OpenJDKでは動作しません)
- Gradle Version: 6.4.1
Terminalから以下のコマンドで表示できています。なお、Androidエミュレータを起動したから以下を実行してください。
$ ./gradlew clean lint test
$ ./gradlew connectedAndroidTest
以上でHTML形式のレポートが app/build/reports/
にできているはずですのでブラウザで表示してください。
※1 ./gradlew connectedAndroidTest
はAndroidデバイス(物理or仮想)が接続されていないと動作しません。
※2 テスト開始に失敗する可能性があるので、その場合は何度か試してください。
app/build/reports/lint-results.html
: Lintの結果レポートapp/build/reports/tests
: ターゲットBuild毎のテスト結果レポートapp/build/reports/coverage
: JaCoCoからのカバレッジレポート(UnitTestとUIテストが統合されて表示されます)app/build/reports/androidTests/connected
: UIテストの結果レポート
$ ./gradlew clean lint jacocoTestReport
app/build/reports/lint-results.html
: Lintの結果レポートapp/build/reports/tests
: ターゲットBuild毎のテスト結果レポートapp/build/jacoco/jacocoHtml
: UnitTestのみのテスト結果レポート
以下の内容は、100%自信を持ってとは言えない調査レベルで、動作させてみた傾向から以下は言えるだろう、というニュアンスです。
- JaCoCoに関して
./gradlew jacocoTestReport
を実施することで、Insttrumentedテストを知なくとも、UIテスト0%の状態で結果を得ることができる。- OpenJDKでは動作しない(jdkがAndroid Studioのデフォルトなので、Terminalから動作させる場合のみ注意)
Apache License 2.0 です。詳細はLICENSE を御覧ください。
Copyright 2020 Ryoya Kawai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.