Skip to content

Instantly share code, notes, and snippets.

@hernandazevedo
Last active June 16, 2024 11:28
Show Gist options
  • Save hernandazevedo/4c19558db2f138c99e3c24838cccf307 to your computer and use it in GitHub Desktop.
Save hernandazevedo/4c19558db2f138c99e3c24838cccf307 to your computer and use it in GitHub Desktop.
Bitrise configuration + Jacoco for Junit + Instrumentation tests + Vitual Device Testing
---
format_version: 1.4.0
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
workflows:
ci:
steps:
- activate-ssh-key@4.0.3:
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
- git-clone@4.0.14: {}
- cache-pull@2.0.1: {}
- script@1.1.5:
title: Do anything with Script step
- install-missing-android-tools@2.3.5:
inputs:
- gradlew_path: "$PROJECT_LOCATION/gradlew"
- android-detekt@0.0.2:
inputs:
- module: "$MODULE"
- android-lint@0.9.6:
inputs:
- project_location: "$PROJECT_LOCATION"
- module: "$MODULE"
- variant: "$VARIANT"
- gradle-runner:
inputs:
- gradle_task: assembleDebug assembleDebugAndroidTest
- gradle_file: "build.gradle"
- virtual-device-testing-for-android@1.1.1:
inputs:
- environment_variables: |-
coverage=true
coverageFile=/sdcard/coverage.ec
- directories_to_pull: "/sdcard/"
- download_test_results: 'true'
- use_verbose_log: 'true'
- test_type: instrumentation
- android-unit-test@0.11.1:
inputs:
- project_location: "$PROJECT_LOCATION"
- module: "$MODULE"
- arguments: jacocoTestReport
- variant: "$VARIANT"
- codecov@1.1.6:
run_if: true
is_skippable: false
inputs:
- CODECOV_TOKEN: "$CODECOV_TOKEN"
- deploy-to-bitrise-io@1.6.0: {}
- cache-push@2.2.0:
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:
- activate-ssh-key@4.0.3:
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
- git-clone@4.0.14: {}
- change-android-versioncode-and-versionname@1.1.1:
inputs:
- new_version_name: "$BITRISE_GIT_TAG"
- build_gradle_path: "$PROJECT_LOCATION/$MODULE/build.gradle"
- cache-pull@2.0.1: {}
- install-missing-android-tools@2.3.5:
inputs:
- gradlew_path: "$PROJECT_LOCATION/gradlew"
- android-build@0.9.5:
inputs:
- project_location: "$PROJECT_LOCATION"
- module: "$MODULE"
- variant: "$VARIANT"
- script@1.1.5:
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
- git-commit-changelog@1.0.5: {}
- github-release@0.10.0:
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"
- deploy-to-bitrise-io@1.6.0: {}
- 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"
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'
])])
}
@hernandazevedozup
Copy link

hernandazevedozup commented Oct 7, 2020

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