Last active
June 16, 2024 11:28
-
-
Save hernandazevedo/4c19558db2f138c99e3c24838cccf307 to your computer and use it in GitHub Desktop.
Bitrise configuration + Jacoco for Junit + Instrumentation tests + Vitual Device Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
format_version: 1.4.0 | |
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git | |
workflows: | |
ci: | |
steps: | |
- [email protected]: | |
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}' | |
- [email protected]: {} | |
- [email protected]: {} | |
- [email protected]: | |
title: Do anything with Script step | |
- [email protected]: | |
inputs: | |
- gradlew_path: "$PROJECT_LOCATION/gradlew" | |
- [email protected]: | |
inputs: | |
- module: "$MODULE" | |
- [email protected]: | |
inputs: | |
- project_location: "$PROJECT_LOCATION" | |
- module: "$MODULE" | |
- variant: "$VARIANT" | |
- gradle-runner: | |
inputs: | |
- gradle_task: assembleDebug assembleDebugAndroidTest | |
- gradle_file: "build.gradle" | |
- [email protected]: | |
inputs: | |
- environment_variables: |- | |
coverage=true | |
coverageFile=/sdcard/coverage.ec | |
- directories_to_pull: "/sdcard/" | |
- download_test_results: 'true' | |
- use_verbose_log: 'true' | |
- test_type: instrumentation | |
- [email protected]: | |
inputs: | |
- project_location: "$PROJECT_LOCATION" | |
- module: "$MODULE" | |
- arguments: jacocoTestReport | |
- variant: "$VARIANT" | |
- [email protected]: | |
run_if: true | |
is_skippable: false | |
inputs: | |
- CODECOV_TOKEN: "$CODECOV_TOKEN" | |
- [email protected]: {} | |
- [email protected]: | |
inputs: | |
- cache_paths: |- | |
$BITRISE_CACHE_DIR | |
$HOME/.gradle | |
./.gradle | |
- ignore_check_on_paths: |- | |
$HOME/.gradle/caches/*.lock | |
$HOME/.gradle/caches/*.bin | |
./.gradle/*.lock | |
./.gradle/*.bin | |
ci_deploy: | |
steps: | |
- [email protected]: | |
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}' | |
- [email protected]: {} | |
- [email protected]: | |
inputs: | |
- new_version_name: "$BITRISE_GIT_TAG" | |
- build_gradle_path: "$PROJECT_LOCATION/$MODULE/build.gradle" | |
- [email protected]: {} | |
- [email protected]: | |
inputs: | |
- gradlew_path: "$PROJECT_LOCATION/gradlew" | |
- [email protected]: | |
inputs: | |
- project_location: "$PROJECT_LOCATION" | |
- module: "$MODULE" | |
- variant: "$VARIANT" | |
- [email protected]: | |
title: Do anything with Script step | |
inputs: | |
- content: |- | |
#!/usr/bin/env bash | |
wget https://github.com/github/hub/releases/download/v2.7.1/hub-linux-amd64-2.7.1.tgz | |
tar zvxvf hub-linux-amd64-2.7.1.tgz | |
sudo ./hub-linux-amd64-2.7.1/install | |
# Setup autocomplete for bash: | |
mkdir -p ~/.bash/completions | |
mv ./hub-linux-amd64-2.7.1/etc/hub.bash_completion.sh ~/.bash/completions/_hub | |
echo "if [ -f ~/.bash/completions/_hub ]; then" >> ~/.bashrc | |
echo " . ~/.bash/completions/_hub" >> ~/.bashrc | |
echo "fi" >> ~/.bashrc | |
# add alias | |
echo "eval "$(hub alias -s)"" >> ~/.bashrc | |
# Cleanup | |
rm -rf hub-linux-amd64-2.7.1 | |
hub version | |
set -e | |
# Authorize hub | |
mkdir -p ~/.config/ | |
cat << EOF > ~/.config/hub | |
github.com: | |
- user: "$GITHUB_USERNAME" | |
oauth_token: "$GITHUB_TOKEN_ACESS" | |
protocol: https | |
EOF | |
set +e | |
cd $PROJECT_LOCATION | |
pwd | |
# errors if release doesn't exist | |
hub release delete $BITRISE_GIT_TAG | |
exit 0 | |
- [email protected]: {} | |
- [email protected]: | |
inputs: | |
- body: |- | |
Release $BITRISE_GIT_TAG | |
Changes | |
$COMMIT_CHANGELOG | |
- draft: 'no' | |
- api_token: "$GITHUB_TOKEN_ACESS" | |
- username: "$GITHUB_USERNAME" | |
- files_to_upload: "$BITRISE_APK_PATH" | |
- name: "$BITRISE_GIT_TAG" | |
- [email protected]: {} | |
- cache-push: | |
inputs: | |
- cache_paths: |- | |
$BITRISE_CACHE_DIR | |
$HOME/.gradle | |
./.gradle | |
- ignore_check_on_paths: |- | |
$HOME/.gradle/caches/*.lock | |
$HOME/.gradle/caches/*.bin | |
./.gradle/*.lock | |
./.gradle/*.bin | |
app: | |
envs: | |
- opts: | |
is_expand: false | |
PROJECT_LOCATION: "." | |
- opts: | |
is_expand: false | |
MODULE: app | |
- opts: | |
is_expand: false | |
VARIANT: debug | |
- GRADLEW_PATH: "./gradlew" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'jacoco' | |
jacoco { | |
toolVersion = '0.8.5' | |
} | |
def fileFilter = ['**/R.class', | |
'**/R$*x.class', | |
'**/BuildConfig.*', | |
'**/Manifest*.*', | |
'**/*Test*.*', | |
'**/*$*', | |
'android/**/*.*', | |
'**/*Function*', | |
'**/*_impl*', | |
'**/*.DefaultImpls.*'] | |
task jacocoTestReport(type: JacocoReport, overwrite: true) { | |
def kotlinSrc = "$project.projectDir/src/main/kotlin" | |
def javaSrc = "$project.projectDir/src/main/java" | |
def javaClasses = fileTree(dir: "$project.buildDir/intermediates/javac/debug", excludes: fileFilter) | |
def kotlinClasses = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter) | |
def dependencyTasks | |
if (project.plugins.hasPlugin('com.android.application') || | |
project.plugins.hasPlugin("com.android.library")) { | |
dependencyTasks = ['testDebugUnitTest'] | |
} else { | |
kotlinClasses = fileTree(dir: "$project.buildDir/classes/kotlin/main", excludes: fileFilter) | |
dependencyTasks = ['test'] | |
} | |
dependsOn { | |
dependencyTasks | |
} | |
reports { | |
xml.enabled = true | |
html.enabled = true | |
} | |
getSourceDirectories().setFrom([javaSrc, kotlinSrc]) | |
getClassDirectories().setFrom([javaClasses, kotlinClasses]) | |
getExecutionData().setFrom([fileTree(dir: project.buildDir, includes: [ | |
'jacoco/testDebugUnitTest.exec', 'outputs/code_coverage/debugAndroidTest/connected/*.ec' | |
])], [fileTree(dir: "${System.env.VDTESTING_DOWNLOADED_FILES_DIR}", includes: [ | |
'*sdcard_coverage.ec' | |
])]) | |
} |
Hi, the output reports from jacoco can be found on your app build dir once the jacocoTestReport is executed. Remember that this must be done after the execution of the instrumentation tests on an apk with coverage enabled to generate the *.ec files. In the configuration above theses files are automatically dowloaded to the Linux instance after the virtual device testing step(in that case, firebase test lab) and saved on VDTESTING_DOWNLOADED_FILES_DIR
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thank you for sharing this. Where is the output of jacocoTestReport found once this is executed?