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

ci: functional tests #16

Merged
merged 51 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c542141
Add message view test
merlinpaypal Nov 29, 2023
dfea4fe
Add LoggerTest
merlinpaypal Nov 29, 2023
fb24392
Fix warnings
merlinpaypal Nov 29, 2023
253df71
Add coroutine test lib
merlinpaypal Nov 29, 2023
288ba16
Update cleartext for local tests
merlinpaypal Nov 30, 2023
39de946
Change env / API to be injectable
merlinpaypal Nov 30, 2023
c7f6f82
Update env test
merlinpaypal Nov 30, 2023
c77270a
Lint
merlinpaypal Nov 30, 2023
ebbc9ce
Update ApiTest
merlinpaypal Nov 30, 2023
eaab4a7
Extract hash state logic
merlinpaypal Nov 30, 2023
d094f4c
Add blank tests
merlinpaypal Nov 30, 2023
d4b3e88
Lint
merlinpaypal Nov 30, 2023
46ce8cd
Merge
merlinpaypal Nov 30, 2023
bb5cd7f
Update tests
merlinpaypal Dec 18, 2023
ef715ce
Add more API tests
merlinpaypal Dec 18, 2023
b738975
Set API functions to internal
merlinpaypal Dec 18, 2023
a336a52
Update workflow
merlinpaypal Dec 18, 2023
78d5efb
Remove demo test
merlinpaypal Dec 18, 2023
05fcec4
Split job for tests
merlinpaypal Dec 18, 2023
8c49b9e
Lint tests
merlinpaypal Dec 18, 2023
ef6832d
Lint storage tests
merlinpaypal Dec 18, 2023
d21a15d
Temp turn off failing tests
merlinpaypal Dec 19, 2023
aa3cb5b
Try tests with macos
merlinpaypal Dec 19, 2023
5883047
Turn off failing tests with comments
merlinpaypal Dec 19, 2023
208feed
Try splitting query for test
merlinpaypal Dec 19, 2023
57a53b0
Add debug flag
merlinpaypal Dec 19, 2023
adacb15
Switch to info flag
merlinpaypal Dec 19, 2023
63d1444
Use .info
merlinpaypal Dec 19, 2023
a36c39d
Split query assertions
merlinpaypal Dec 19, 2023
02744c5
Remove null from UUID values
merlinpaypal Dec 19, 2023
bb69a7d
Uncomment LoggerTest
merlinpaypal Dec 19, 2023
e388ba9
Set tests to clear device
merlinpaypal Dec 21, 2023
cbdf07f
Lint
merlinpaypal Dec 21, 2023
8813ad4
Fix logs command
merlinpaypal Dec 21, 2023
ee87f3e
Update script
merlinpaypal Dec 21, 2023
ecd96fb
Update script
merlinpaypal Dec 21, 2023
f6e3279
Update workflow
merlinpaypal Dec 29, 2023
fc3897c
Update script
merlinpaypal Jan 2, 2024
3e0746a
Fix test
merlinpaypal Jan 2, 2024
6f19556
Update workflow
merlinpaypal Jan 2, 2024
b8d60fb
Update workflow
merlinpaypal Jan 2, 2024
e21c6d0
Use xml instead
merlinpaypal Jan 2, 2024
457e8b9
Make test pass again
merlinpaypal Jan 2, 2024
0158769
Add coverage output
merlinpaypal Jan 2, 2024
ca8deb6
Fix coverage workflow step
merlinpaypal Jan 2, 2024
9e329b7
Change coverage report
merlinpaypal Jan 2, 2024
070cd04
Change path
merlinpaypal Jan 2, 2024
d7ecbee
Update exclusion list
merlinpaypal Jan 2, 2024
f2a5109
Update version
merlinpaypal Jan 2, 2024
fc85239
Add debug step
merlinpaypal Jan 2, 2024
16aab1c
Merge branch 'develop' into ci/func-and-release
merlinpaypal Jan 12, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# after build and unit tests are finished, publish all modules at once
# to help reduce the probability of failure when interacting with sonatype servers
release:
name: Publish To Maven
name: Release
needs: [lint, test, build]
runs-on: ubuntu-latest
steps:
Expand Down
69 changes: 66 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ concurrency:
cancel-in-progress: true

jobs:
test:
name: Test
test_unit:
name: Unit Tests
runs-on: ubuntu-latest

steps:
Expand All @@ -21,6 +21,69 @@ jobs:
distribution: 'microsoft'
cache: gradle

- name: Run Tests
- name: Run Unit Tests
run: ./gradlew testReleaseUnitTest
continue-on-error: false

test_unit_coverage:
name: Unit Tests Coverage
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Run Unit Tests Coverage
run: ./gradlew koverXmlReportDebug

- name: Show Coverage Report XML
run: cat library/build/reports/kover/reportDebug.xml

- name: Add coverage report to PR
id: kover
uses: mi-kas/kover-report@v1.8
with:
path: ${{ github.workspace }}/library/build/reports/kover/reportDebug.xml
title: Code Coverage
update-comment: true
min-coverage-overall: 85
min-coverage-changed-files: 85
coverage-counter-type: LINE

test_instrumentation:
name: Instrumentation Tests
runs-on: macos-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Run Instrumentation Tests
uses: ReactiveCircus/android-emulator-runner@v2
with:
api-level: 23
target: google_apis
arch: x86_64
script: ./gradlew connectedCheck --info
continue-on-error: true

- name: Show Test XML
run: |
cat library/build/outputs/androidTest-results/connected/*.xml
echo ""
error_count=$(grep "<failure>" library/build/outputs/androidTest-results/connected/*.xml | wc -l | awk '{$1=$1};1')
if [[ "$error_count" -ne "0" ]]; then echo "Tests failed. See above"; exit 1; fi

This file was deleted.

4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jul 12 10:12:47 EDT 2023
#Tue Dec 19 11:47:10 EST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 21 additions & 14 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ android {
versionCode modules.sdkVersionCode
versionName modules.sdkVersionName
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
testInstrumentationRunnerArguments clearPackageData: 'true'
consumerProguardFiles 'consumer-rules.pro'

buildConfigField('String', 'INTEGRATION_TYPE', "\"NATIVE_ANDROID\"")
Expand All @@ -31,13 +32,17 @@ android {
viewBinding = true
}

buildTypes {
release {
version = android.defaultConfig.versionName // had to add this to get the version in the build
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildTypes {
release {
version = android.defaultConfig.versionName
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
resValue("string", "clear_text_config","false")
}
debug {
resValue("string", "clear_text_config","true")
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -49,6 +54,7 @@ android {
}

testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
unitTests.all {
useJUnitPlatform()
testLogging {
Expand All @@ -65,20 +71,17 @@ tasks.withType(Test) {
koverReport {
androidReports('debug') {
filters {
// includes {
// classes(
// 'PayPalErrors\$*'
// )
// }
excludes {
classes(
// config
'com.paypal.messages.config.message.PayPalMessageEventsCallbacks\$*',
'com.paypal.messages.config.message.PayPalMessageViewStateCallbacks\$*',
'com.paypal.messages.config.modal.ModalEvents\$*',
// extensions,
'com.paypal.messages.extensions.*',
'com.paypal.messages.extensions.Int*',
// io
'com.paypal.messages.io.Api',
'com.paypal.messages.io.Api\$*',
'com.paypal.messages.io.Api\$Endpoints',
'com.paypal.messages.io.ApiMessageData',
'com.paypal.messages.io.ApiHashData',
Expand All @@ -96,6 +99,7 @@ koverReport {
'*Activity\$*',
'com.paypal.messages.PayPalMessageView*',
'com.paypal.messages.RoundedWebView',
'com.paypal.messages.RoundedWebView\$*',
'*.databinding.*',
'*.BuildConfig'
)
Expand All @@ -107,7 +111,7 @@ koverReport {
dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'com.squareup.okhttp3:okhttp:4.8.0'

Expand All @@ -117,8 +121,11 @@ dependencies {
testImplementation 'org.mockito.kotlin:mockito-kotlin:5.1.0'
testImplementation 'io.mockk:mockk:1.13.7'

androidTestUtil 'androidx.test:orchestrator:1.4.2'
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1'
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.8.0'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.paypal.messages

import android.widget.TextView
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.paypal.messages.config.PayPalMessageOfferType
import com.paypal.messages.config.ProductGroup
import com.paypal.messages.config.modal.ModalCloseButton
import com.paypal.messages.io.ApiMessageData
import com.paypal.messages.io.ApiResult
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import java.util.UUID
import com.paypal.messages.config.message.PayPalMessageConfig as MessageConfig
import com.paypal.messages.config.message.PayPalMessageData as MessageData

@RunWith(AndroidJUnit4::class)
class PayPalMessageViewTest {
// @get:Rule
// val activityTestRule = ActivityTestRule(TestActivity::class.java)
//
// @get:Rule
// val activityScenarioRule = ActivityScenarioRule(TestActivity::class.java)

private val defaultMain = "Test main"
private val defaultDisclaimer = "Test disclaimer"
private val response = ApiMessageData.Response(
meta = ApiMessageData.Metadata(
creditProductGroup = ProductGroup.PAYPAL_CREDIT,
offerCountryCode = "",
offerType = PayPalMessageOfferType.PAY_LATER_PAY_IN_1,
messageType = "",
modalCloseButton = ModalCloseButton(
0,
0,
0,
0,
"",
"",
),
variables = ApiMessageData.Variables(logoPlaceholder = ""),
merchantCountryCode = "",
creditProductIdentifiers = List(0) { "" },
debugId = "",
fdata = "",
trackingKeys = List(0) { "" },
originatingInstanceId = UUID.randomUUID(),
),
content = ApiMessageData.ContentOptions(
default = ApiMessageData.ContentDetails(main = defaultMain, disclaimer = defaultDisclaimer),
generic = ApiMessageData.ContentDetails(main = "", disclaimer = ""),
),
)

@Test
fun testUpdateMessageContent() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val payPalMessageView = PayPalMessageView(
context = context,
config = MessageConfig(MessageData(clientID = "test_client_id")),
)

payPalMessageView.onActionCompleted(ApiResult.Success(response))

val messageTextView = payPalMessageView.findViewById<TextView>(R.id.content)
assertTrue(messageTextView.text.toString().contains(defaultMain))
assertTrue(messageTextView.text.toString().contains(defaultDisclaimer))
}
}
15 changes: 15 additions & 0 deletions library/src/androidTest/java/com/paypal/messages/TestActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.paypal.messages

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class TestActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(layout)
}

companion object {
var layout: Int = 0
}
}
Loading