Skip to content

Commit

Permalink
ci: added Android coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
semirp committed May 15, 2024
1 parent 3bd70af commit 5d419bf
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .github/actions/sonar/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ inputs:
description: Sonar host URL
required: true
coverage-file-name:
description: Name of the generic coverage file
description: Name of the LCOV coverage file
required: true
coverage-file-name-android:
description: Name of the Kover coverage file
required: true
branch:
description: Branch
Expand Down Expand Up @@ -41,6 +44,7 @@ runs:
echo "sonar.pullrequest.base=${{ inputs.base-branch }}" >> sonar-project.properties
echo "sonar.scm.revision=${{ inputs.pull-request-sha }}" >> sonar-project.properties
echo "sonar.javascript.lcov.reportPaths=${{ inputs.coverage-file-name }}" >> sonar-project.properties
echo "sonar.coverage.jacoco.xmlReportPaths=${{ inputs.coverage-file-name-android }}" >> sonar-project.properties
- name: Run Sonar
shell: bash
run: |
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/unit-tests-and-code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ jobs:
name: coverage-file
path: coverage

- name: Run Android unit tests and generate coverage
run: bundle exec fastlane android run_unit_tests_coverage

- uses: actions/upload-artifact@master
with:
name: coverage-file-android
path: package/sdk/android/build/reports/kover

sonarcloud:
needs:
- run-unit-tests
Expand All @@ -36,6 +44,10 @@ jobs:
with:
name: coverage-file
path: coverage
- uses: actions/download-artifact@master
with:
name: coverage-file-android
path: kover
- name: SonarCloud Scan
uses: ./.github/actions/sonar
with:
Expand All @@ -47,3 +59,4 @@ jobs:
base-branch: ${{ github.base_ref }}
pull-request-sha: ${{ github.event.pull_request.head.sha }}
coverage-file-name: ./coverage/lcov.info
coverage-file-name-android: ./kover/reportsRelease.xml
3 changes: 3 additions & 0 deletions fastlane/AndroidFastFile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ platform :android do
save_browserstack_id(browserstack_id: ENV['BROWSERSTACK_APP_ID'])
end

lane :run_unit_tests_coverage do
gradle(task: "clean koverXmlReportRelease", project_dir: 'packages/example/android/')
end

desc 'Store the Browserstack ID into a file'
private_lane :save_browserstack_id do |options|
Expand Down
19 changes: 18 additions & 1 deletion packages/sdk/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['ReactNative_kotlinVersion']

def kover_version = '0.7.6'
repositories {
google()
mavenCentral()
Expand All @@ -13,12 +13,14 @@ buildscript {
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "org.jetbrains.kotlinx:kover-gradle-plugin:$kover_version"
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'
apply from: "./config/coverage/kover.gradle"

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNative_' + name]
Expand All @@ -37,6 +39,8 @@ android {
minSdkVersion 21
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')

testInstrumentationRunnerArguments runnerBuilder: 'de.mannodermaus.junit5.AndroidJUnit5Builder'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -58,6 +62,13 @@ android {
kotlinOptions {
freeCompilerArgs += '-Xjvm-default=all'
}
testOptions {
execution = 'ANDROIDX_TEST_ORCHESTRATOR'

unitTests.all {
useJUnitPlatform()
}
}
}

repositories {
Expand Down Expand Up @@ -139,4 +150,10 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3"
implementation 'io.primer:android:2.27.0'

testImplementation 'io.mockk:mockk:1.13.10'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2'
testImplementation 'de.mannodermaus.junit5:android-test-runner:1.3.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.primerioreactnative.utils

import com.primerioreactnative.datamodels.ErrorTypeRN
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

internal class ErrorHelperTest {

// Create a mock ErrorTypeRN instance
private val errorType = ErrorTypeRN.InvalidVaultedPaymentMethodId

@Test
fun `errorTo should create PrimerErrorRN with correct properties`() {
// Mock message
val errorMessage = "This is an error message"

// Call the infix function
val primerError = errorType errorTo errorMessage

// Verify the errorId and message are set correctly in the PrimerErrorRN object
assertEquals(errorType.errorId, primerError.errorId)
assertEquals(errorMessage, primerError.description)
}
}

0 comments on commit 5d419bf

Please sign in to comment.