Skip to content

Commit

Permalink
Add Google Pay tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samer-stripe committed Sep 3, 2024
1 parent 16b2da4 commit 590dd8e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ workflows:
after_run:
- conclude_all
steps:
- android-build-for-ui-testing:
- android-build-for-ui-testing@0:
inputs:
- module: paymentsheet-example
- variant: debug
- virtual-device-testing-for-android:
- arguments: -PSTRIPE_SHOULD_RUN_GOOGLE_PAY_TESTS=true
- virtual-device-testing-for-android@1:
inputs:
- test_type: instrumentation
- auto_google_login: true
Expand Down
5 changes: 5 additions & 0 deletions paymentsheet-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def getGooglePlacesApiKey() {
return findProperty('STRIPE_PAYMENTSHEET_EXAMPLE_GOOGLE_PLACES_API_KEY') ?: ""
}

def getShouldRunGooglePayTests() {
return project.hasProperty("STRIPE_SHOULD_RUN_GOOGLE_PAY_TESTS") && project.STRIPE_SHOULD_RUN_GOOGLE_PAY_TESTS.contains("true")
}

dependencies {
implementation project(':payments')
implementation project(':stripecardscan')
Expand Down Expand Up @@ -85,6 +89,7 @@ android {

testInstrumentationRunner "com.karumi.shot.ShotTestRunner"

buildConfigField "boolean", "SHOULD_RUN_GOOGLE_PAY_TESTS", "${getShouldRunGooglePayTests()}"
buildConfigField "boolean", "IS_RUNNING_IN_CI", "$gradle.ext.isCi"
buildConfigField "boolean", "IS_NIGHTLY_BUILD", "$gradle.ext.isNightlyBuild"
buildConfigField "boolean", "IS_BROWSERSTACK_BUILD", "$gradle.ext.isBrowserstackBuild"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,50 @@ package com.stripe.android.lpm
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.paymentsheet.example.playground.settings.Country
import com.stripe.android.utils.GooglePayTest
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class TestGooglePay : BasePlaygroundTest() {
@Test
@GooglePayTest
fun testUnitedStates() {
testDriver.confirmWithGooglePay(Country.US)
}

@Test
@GooglePayTest
fun testFrance() {
testDriver.confirmWithGooglePay(Country.FR)
}

@Test
@GooglePayTest
fun testGreatBritain() {
testDriver.confirmWithGooglePay(Country.GB)
}

@Test
@GooglePayTest
fun testAustralia() {
testDriver.confirmWithGooglePay(Country.AU)
}

@Test
@GooglePayTest
fun testBrazil() {
testDriver.confirmWithGooglePay(Country.BR)
}

@Test
@GooglePayTest
fun testJapan() {
testDriver.confirmWithGooglePay(Country.JP)
}

@Test
@GooglePayTest
fun testMexico() {
testDriver.confirmWithGooglePay(Country.MX)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.stripe.android.utils
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE)
annotation class GooglePayTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.stripe.android.utils

import com.stripe.android.paymentsheet.example.test.BuildConfig
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement

class GooglePayTestRule : TestRule {
override fun apply(base: Statement, description: Description): Statement {
return object : Statement() {
override fun evaluate() {
if (description.hasGooglePayTestAnnotation()) {
if (shouldRunGooglePayTests()) {
base.evaluate()
}
} else {
base.evaluate()
}
}
}
}

private fun Description.hasGooglePayTestAnnotation(): Boolean {
for (annotation in annotations) {
if (annotation is GooglePayTest) {
return true
}
}

return false
}

private fun shouldRunGooglePayTests(): Boolean {
return BuildConfig.SHOULD_RUN_GOOGLE_PAY_TESTS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TestRules private constructor(
}
}.around(Timeout.seconds(INDIVIDUAL_TEST_TIMEOUT_SECONDS))
.around(CleanupChromeRule)
.around(GooglePayTestRule())

return TestRules(chain, composeTestRule)
}
Expand Down

0 comments on commit 590dd8e

Please sign in to comment.