Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LD-145] Add code coverage for E2E tests. #199

Merged
merged 17 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ jobs:
android-tests:
name: Run UI tests on Firebase Test Lab
runs-on: ubuntu-20.04
permissions:
pull-requests: write

steps:
- name: Checkout
Expand Down Expand Up @@ -143,13 +145,16 @@ jobs:
--timeout="20m" \
--results-dir="${{ steps.generate-dir.outputs.results_dir }}" \
--results-bucket="${{ steps.generate-dir.outputs.bucket }}" \
--environment-variables "clearPackageData=true,coverage=true,coverageFilePath=/sdcard/Download/"
--environment-variables "clearPackageData=true,coverage=true,coverageFilePath=/sdcard/Download/" \
--directories-to-pull /sdcard/Download

- name: Download test results from Firebase Test Lab
if: always()
run: |-
mkdir "app/build/test-results"
mkdir "app/build/test-results/instrumentation_results"
gsutil cp -r "gs://${{ steps.generate-dir.outputs.bucket }}/${{ steps.generate-dir.outputs.results_dir }}/Pixel2.arm-33-en-portrait/test_result_1.xml" "app/build/test-results/results.xml"
gsutil cp -r "gs://${{ steps.generate-dir.outputs.bucket }}/${{ steps.generate-dir.outputs.results_dir }}/Pixel2.arm-33-en-portrait/artifacts/sdcard/Download/*.ec" "app/build/test-results/instrumentation_results"

- name: Upload tests results
if: always()
Expand All @@ -160,6 +165,31 @@ jobs:
*/build/test-results/**
retention-days: 5

- name: Run instrumentation code coverage
run: ./gradlew instrumentationCodeCoverage
env:
LOUDIUS_CLIENT_SECRET: ${{ secrets.LOUDIUS_CLIENT_SECRET }}
LOUDIUS_CLIENT_ID: ${{ secrets.LOUDIUS_CLIENT_ID }}
LOUDIUS_GITHUB_USER_PASSWORD: ${{ secrets.LOUDIUS_GITHUB_USER_PASSWORD }}
LOUDIUS_GITHUB_USER_NAME: ${{ secrets.LOUDIUS_GITHUB_USER_NAME }}
LOUDIUS_GITHUB_USER_OTP_SECRET: ${{ secrets.LOUDIUS_GITHUB_USER_OTP_SECRET }}

- name: Store HTML coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: |
*/build/reports/jacoco/instrumentationCodeCoverage/html/**

- name: Add coverage to PR
if: ${{ github.event_name != 'schedule' }}
id: jacoco
uses: madrapps/[email protected]
with:
paths: |
*/build/reports/jacoco/instrumentationCodeCoverage/instrumentationCodeCoverage.xml
token: ${{ secrets.GITHUB_TOKEN }}

test-license-headers:
name: Ensure license headers are added
runs-on: ubuntu-20.04
Expand Down
41 changes: 40 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
versionName "1.0"

testInstrumentationRunner "com.appunite.loudius.util.InstrumentationTestRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
testInstrumentationRunnerArguments clearPackageData: 'true', coverage: 'true', coverageFilePath: '/sdcard/Download/'
vectorDrawables {
useSupportLibrary true
}
Expand All @@ -54,6 +54,7 @@ android {
}
debug{
enableUnitTestCoverage true
testCoverageEnabled true
}
}
compileOptions {
Expand Down Expand Up @@ -145,6 +146,44 @@ tasks.register('codeCoverage', JacocoReport) {

}

tasks.register('instrumentationCodeCoverage', JacocoReport) {

reports {
html.required.set(true)
xml.required.set(true)
}

classDirectories.setFrom(
fileTree(project.buildDir) {
include("**/tmp/kotlin-classes/debug/**")
exclude(
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
"**/*Application.*",
'**/Manifest*.*',
'**/*Test*.*',
'**/android/**/*.*',
'**/androidx/**/*.*',
'**/airbnb/**/*.*',
"**/di/**/*.*",
'**/*Dagger*.*',
"**/*Screen*"
)
}
)

sourceDirectories.setFrom(fileTree(
dir: project.projectDir,
includes: [
"src/main/java/**",
"src/main/kotlin/**"
]))

executionData.setFrom(
fileTree(dir: "${buildDir}/test-results/instrumentation_results", includes: ['*.ec']))
}

dependencies {
api project(':components')

Expand Down
2 changes: 1 addition & 1 deletion components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ Topbar is a component on the top of the screen.
| Variant | Snapshot |
|--------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Topbar with back navigation**<br />[Source Code](../components/src/main/java/com/appunite/loudius/components/components/LoudiusTopAppBar.kt#L61-L70) | <img src="src/test/snapshots/images/com.appunite.loudius_PaparazziShowkaseTests_preview_tests[Default Group-LoudiusTopAppBar,1,light].png" /> |
| **Topbar with no navigation**<br /> [Source Code](../components/src/main/java/com/appunite/loudius/components/components/LoudiusTopAppBar.kt#L72-L80) | <img src="src/test/snapshots/images/com.appunite.loudius_PaparazziShowkaseTests_preview_tests[Default Group-LoudiusTopAppBarWithoutBackButton,1,light].png" /> |
| **Topbar with no navigation**<br /> [Source Code](../components/src/main/java/com/appunite/loudius/components/components/LoudiusTopAppBar.kt#L72-L80) | <img src="src/test/snapshots/images/com.appunite.loudius_PaparazziShowkaseTests_preview_tests[Default Group-LoudiusTopAppBarWithoutBackButton,1,light].png" /> |
Loading