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-139] chore: test coverage report #162

Merged
merged 10 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
20 changes: 19 additions & 1 deletion .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-20.04
permissions:
pull-requests: write

steps:
- name: Checkout
Expand All @@ -36,14 +38,30 @@ jobs:
uses: ./.github/actions/prepare-android-env

- name: Run test
run: ./gradlew test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why is this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is replaced by a task that I created codeCoverage

run: ./gradlew codeCoverage
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/codeCoverage/html/**

- name: Add coverage to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: |
*/build/reports/jacoco/codeCoverage/codeCoverage.xml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we pass the path to the codeCoverage report in xml format to the action

token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why we have here: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}?

debug-mode: true

- name: Upload tests results
if: always()
uses: actions/upload-artifact@v3
Expand Down
53 changes: 51 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'com.android.application'
id 'kotlin-kapt'
id 'org.jetbrains.kotlin.android'
id 'jacoco'
id 'org.jlleitschuh.gradle.ktlint' version '11.6.1'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0'
}
Expand Down Expand Up @@ -43,6 +44,9 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug{
enableUnitTestCoverage true
}
}
compileOptions {
coreLibraryDesugaringEnabled true
Expand Down Expand Up @@ -88,6 +92,50 @@ android {
}
}

tasks.register('codeCoverage', JacocoReport) {
dependsOn 'testDebugUnitTest'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependsOn means that it will execute testDebugUnitTest when triggering codeCoverage and then all that is defined here


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

classDirectories.setFrom(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: The compiled class files without instrumentation. Execution data references instructions in these classes, so they're necessary for locating the actual instructions.

fileTree(project.buildDir) {
include("**/tmp/kotlin-classes/debug/**")
exclude(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can exclude some classes so that we they are not included in the code coverage report

'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
"**/*Application.*",
'**/Manifest*.*',
'**/*Test*.*',
'**/android/**/*.*',
'**/androidx/**/*.*',
'**/airbnb/**/*.*',
"**/di/**/*.*",
'**/*Dagger*.*',
"**/*Screen*"
)
}
)

sourceDirectories.setFrom(fileTree(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the location of the original source code files. Optional, but allows the reporter to map bytecode instructions back to the original sources in order to include them into the report with coverage annotations.

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

executionData.setFrom(fileTree(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location of "execution data", i.e. the coverage data collected by the unit test runner when running the tests against classes instrumented by the JaCoCo agent.

dir: project.buildDir,
includes: [
"**/*.exec",
"**/*.ec"
]))

}

dependencies {
api project(':components')
//Desugaring for use of java.time in api lower then 26
Expand Down Expand Up @@ -141,11 +189,12 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
testImplementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")


//retrofit & okhttp
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0'



testImplementation project(":app-shared-tests")
androidTestImplementation(project(":app-shared-tests")) {
exclude group: 'org.robolectric', module: 'robolectric'
Expand All @@ -164,4 +213,4 @@ tasks.withType(Test) {

kapt {
correctErrorTypes true
}
}
Loading