Skip to content

Commit

Permalink
Remove integration test flavor (#1143)
Browse files Browse the repository at this point in the history
### Description
After we joined all modules into one, we can remove the integration test
flavor. This will simplify things
  • Loading branch information
tonidero committed Jul 20, 2023
1 parent 0cc73a3 commit 67d1147
Show file tree
Hide file tree
Showing 41 changed files with 108 additions and 104 deletions.
10 changes: 4 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,20 @@ jobs:
- android/restore-build-cache
- run:
name: Run Tests
# We are running tests in the "defaults" flavor only. If we ever add/remove flavors, we will need to update
# this command.
command: ./gradlew lint testDefaultsDebugUnitTest testDefaultsReleaseUnitTest
command: ./gradlew lint test
- run:
name: Consolidate artifacts
command: |
mkdir -p build/test-results/
find . -type f -regex ".*/build/test-results/.*xml" -exec cp --parents {} build/test-results/ \;
- run:
name: Kover HTML
command: ./gradlew purchases:koverHtmlReportDefaultsRelease
command: ./gradlew purchases:koverHtmlReportRelease
- run:
name: Kover XML
command: ./gradlew purchases:koverXmlReportDefaultsRelease
command: ./gradlew purchases:koverXmlReportRelease
- codecov/upload:
file: purchases/build/reports/kover/reportDefaultsRelease.xml
file: purchases/build/reports/kover/reportRelease.xml
- android/save-build-cache
- store_artifacts:
path: build/reports
Expand Down
2 changes: 1 addition & 1 deletion .run/Debug tests.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</option>
<option name="taskNames">
<list>
<option value="testDefaultsDebugUnitTest" />
<option value="testDebugUnitTest" />
</list>
</option>
<option name="vmOptions" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Purchases Integration Tests (set purchases module variant before executing)" type="AndroidTestRunConfigurationType" factoryName="Android Instrumented Tests" singleton="true">
<configuration default="false" name="Purchases Integration Tests" type="AndroidTestRunConfigurationType" factoryName="Android Instrumented Tests" singleton="true">
<module name="purchases-android.purchases.androidTest" />
<option name="TESTING_TYPE" value="0" />
<option name="METHOD_NAME" value="" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Release tests.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</option>
<option name="taskNames">
<list>
<option value="testDefaultsReleaseUnitTest" />
<option value="testReleaseUnitTest" />
</list>
</option>
<option name="vmOptions" />
Expand Down
4 changes: 0 additions & 4 deletions base-application.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ android {
defaultConfig {
minSdkVersion minVersion
targetSdkVersion compileVersion
// Library modules have a new dimension used to add extra APIs for integration tests
// Our applications however don't need the extra flavor. This makes sure that we use the
// flavor without the extra APIs in our applications.
missingDimensionStrategy 'extraAPIs', 'defaults'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
16 changes: 8 additions & 8 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,11 @@ platform :android do
new_text: ENV['LOAD_SHEDDER_REVENUECAT_API_KEY'],
paths_of_files_to_update: [constants_path]
)
# Running integration test flavor in order to make backend tests run faster, since the jittering is too
# long in the `defaults` flavor.
gradle(
task: ':purchases:testIntegrationTestDebugUnitTest',
task: ':purchases:testDebugUnitTest',
properties: {
"RUN_INTEGRATION_TESTS" => true
"RUN_INTEGRATION_TESTS" => true,
"minSdkVersion" => 21,
}
)
end
Expand Down Expand Up @@ -221,7 +220,7 @@ platform :android do
def build_purchases_integration_tests(app_name:, api_key:, google_purchase_token:, product_id_to_purchase:,
base_plan_id_to_purchase:, active_entitlements_to_verify: '',
proxy_url: nil, build_type: 'release')
constants_path = './purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/Constants.kt'
constants_path = './purchases/src/androidTest/kotlin/com/revenuecat/purchases/Constants.kt'
replace_text_in_files(
previous_text: "REVENUECAT_API_KEY",
new_text: api_key,
Expand Down Expand Up @@ -472,11 +471,12 @@ def build_purchases_android_test_apk(package_name, apk_name, build_type)
task: ':purchases:assembleAndroidTest',
properties: {
"testApplicationId" => package_name,
"testBuildType" => build_type
"testBuildType" => build_type,
"minSdkVersion" => 21
}
)
apk_path = "../purchases/build/outputs/apk/androidTest/integrationTest/#{build_type}/purchases-integrationTest-#{build_type}-androidTest.apk"
new_apk_path = "../purchases/build/outputs/apk/androidTest/integrationTest/#{build_type}/#{apk_name}.apk"
apk_path = "../purchases/build/outputs/apk/androidTest/#{build_type}/purchases-#{build_type}-androidTest.apk"
new_apk_path = "../purchases/build/outputs/apk/androidTest/#{build_type}/#{apk_name}.apk"
sh "mv #{apk_path} #{new_apk_path}"
copy_artifacts(
target_path: 'purchases/test_artifacts',
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ purchaseTesterMinSdkVersion=21

#Do not sign releases. When calling uploadArchives pass -PRELEASE_SIGNING_ENABLED=true
RELEASE_SIGNING_ENABLED=false
ANDROID_VARIANT_TO_PUBLISH=defaultsRelease
ANDROID_VARIANT_TO_PUBLISH=release
SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=true

Expand Down
23 changes: 11 additions & 12 deletions library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@ android {
compileSdkVersion compileVersion
buildToolsVersion buildToolsVersion

flavorDimensions "extraAPIs"
productFlavors {
defaults {
dimension "extraAPIs"
}
integrationTest {
dimension "extraAPIs"
minSdkVersion 21 // Needed because mockk-android requires API 21
}
}

defaultConfig {
minSdkVersion minVersion
minSdkVersion obtainMinSdkVersion()
targetSdkVersion compileVersion
versionCode 1
versionName "6.8.0-SNAPSHOT"
Expand Down Expand Up @@ -42,3 +31,13 @@ project.afterEvaluate {
// after https://github.com/Kotlin/kotlinx-kover/issues/362 is fixed
project.pluginManager.apply("org.jetbrains.kotlinx.kover")
}

def obtainMinSdkVersion() {
def result = minVersion

if (project.hasProperty("minSdkVersion")) {
result = project.getProperties().get("minSdkVersion").toInteger()
}

result
}
35 changes: 15 additions & 20 deletions purchases/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ android {
buildConfig true
}

productFlavors {
integrationTest {
testApplicationId obtainTestApplicationId()
testBuildType obtainTestBuildType()
packagingOptions {
resources.excludes.add("META-INF/LICENSE.md")
resources.excludes.add("META-INF/LICENSE-notice.md")
}
defaultConfig {
testApplicationId obtainTestApplicationId()
testBuildType obtainTestBuildType()
packagingOptions {
resources.excludes.add("META-INF/LICENSE.md")
resources.excludes.add("META-INF/LICENSE-notice.md")
}
}

Expand Down Expand Up @@ -81,18 +79,15 @@ dependencies {
testImplementation libs.okhttp.mockwebserver
testImplementation libs.playServices.ads.identifier

integrationTestImplementation libs.androidx.appcompat
integrationTestImplementation libs.material
integrationTestImplementation libs.androidx.constraintlayout

androidTestIntegrationTestImplementation libs.androidx.lifecycle.runtime.ktx
androidTestIntegrationTestImplementation libs.androidx.test.espresso.core
androidTestIntegrationTestImplementation libs.androidx.test.runner
androidTestIntegrationTestImplementation libs.androidx.test.rules
androidTestIntegrationTestImplementation libs.androidx.test.junit
androidTestIntegrationTestImplementation libs.assertJ
androidTestIntegrationTestImplementation libs.mockk.android
androidTestIntegrationTestImplementation libs.mockk.agent
androidTestImplementation libs.androidx.appcompat
androidTestImplementation libs.androidx.lifecycle.runtime.ktx
androidTestImplementation libs.androidx.test.espresso.core
androidTestImplementation libs.androidx.test.runner
androidTestImplementation libs.androidx.test.rules
androidTestImplementation libs.androidx.test.junit
androidTestImplementation libs.assertJ
androidTestImplementation libs.mockk.android
androidTestImplementation libs.mockk.agent
}

tasks.dokkaHtmlPartial.configure {
Expand Down
13 changes: 13 additions & 0 deletions purchases/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- Ignoring errors in API <21 since mockk-android is only supported starting in API 21 -->
<uses-sdk tools:overrideLibrary="io.mockk,io.mockk.proxy.android"/>
<application
android:allowBackup="true"
android:label="RevenueCatIntegrationTests"
android:supportsRtl="true"
android:debuggable="true"
tools:ignore="HardcodedDebugMode">
<activity android:name="com.revenuecat.purchases.MainActivity" android:exported="true"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.revenuecat.purchases

import android.os.Bundle
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity

class MainActivity : AppCompatActivity() {
class MainActivity : FragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(LinearLayout(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal fun Purchases.Companion.configure(
overrideBillingAbstract,
forceServerErrors,
forceSigningErrors,
runningIntegrationTests = true,
).also {
@SuppressLint("RestrictedApi")
sharedInstance = it
Expand Down
17 changes: 0 additions & 17 deletions purchases/src/integrationTest/AndroidManifest.xml

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 0 additions & 10 deletions purchases/src/integrationTest/res/values/colors.xml

This file was deleted.

3 changes: 0 additions & 3 deletions purchases/src/integrationTest/res/values/strings.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.Context
import android.content.pm.PackageManager
import android.preference.PreferenceManager
import androidx.annotation.VisibleForTesting
import com.revenuecat.purchases.api.BuildConfig
import com.revenuecat.purchases.common.Anonymizer
import com.revenuecat.purchases.common.AppConfig
import com.revenuecat.purchases.common.Backend
Expand Down Expand Up @@ -45,7 +44,6 @@ import java.util.concurrent.ThreadFactory
internal class PurchasesFactory(
private val apiKeyValidator: APIKeyValidator = APIKeyValidator(),
) {
private val integrationTestFlavor = "integrationTest"

@Suppress("LongMethod", "LongParameterList")
fun createPurchases(
Expand All @@ -55,6 +53,7 @@ internal class PurchasesFactory(
overrideBillingAbstract: BillingAbstract? = null,
forceServerErrors: Boolean = false,
forceSigningError: Boolean = false,
runningIntegrationTests: Boolean = false,
): Purchases {
validateConfiguration(configuration)

Expand All @@ -67,7 +66,7 @@ internal class PurchasesFactory(
proxyURL,
store,
dangerousSettings,
BuildConfig.FLAVOR == integrationTestFlavor,
runningIntegrationTests,
forceServerErrors,
forceSigningError,
)
Expand All @@ -77,8 +76,8 @@ internal class PurchasesFactory(
val sharedPreferencesForETags = ETagManager.initializeSharedPreferences(context)
val eTagManager = ETagManager(sharedPreferencesForETags)

val dispatcher = Dispatcher(service ?: createDefaultExecutor())
val diagnosticsDispatcher = Dispatcher(createDiagnosticsExecutor())
val dispatcher = Dispatcher(service ?: createDefaultExecutor(), runningIntegrationTests)
val diagnosticsDispatcher = Dispatcher(createDiagnosticsExecutor(), runningIntegrationTests)

var diagnosticsFileHelper: DiagnosticsFileHelper? = null
var diagnosticsTracker: DiagnosticsTracker? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ internal enum class Delay(val minDelay: Duration, val maxDelay: Duration) {

internal open class Dispatcher(
private val executorService: ExecutorService,
private val runningIntegrationTests: Boolean = false,
) {
private companion object {
const val INTEGRATION_TEST_DELAY_PERCENTAGE: Double = .01
}

abstract class AsyncCall : Runnable {
@Throws(JSONException::class, IOException::class)
Expand Down Expand Up @@ -56,7 +60,10 @@ internal open class Dispatcher(
synchronized(this.executorService) {
if (!executorService.isShutdown) {
val future = if (delay != Delay.NONE && executorService is ScheduledExecutorService) {
val delayToApply = (delay.minDelay.inWholeMilliseconds..delay.maxDelay.inWholeMilliseconds).random()
var delayToApply = (delay.minDelay.inWholeMilliseconds..delay.maxDelay.inWholeMilliseconds).random()
if (runningIntegrationTests) {
delayToApply = (delayToApply * INTEGRATION_TEST_DELAY_PERCENTAGE).toLong()
}
executorService.schedule(command, delayToApply, TimeUnit.MILLISECONDS)
} else {
executorService.submit(command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.revenuecat.purchases.common

import kotlin.time.Duration.Companion.milliseconds

// These values are modified in the `integrationTest` flavor to make the tests run faster.
internal object DispatcherConstants {
val jitterDelay = 5000L.milliseconds
val jitterLongDelay = 10000L.milliseconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ internal abstract class BaseBackendIntegrationTest {
every { forceServerErrors } returns false
every { forceSigningErrors } returns false
}
dispatcher = Dispatcher(Executors.newSingleThreadScheduledExecutor())
diagnosticsDispatcher = Dispatcher(Executors.newSingleThreadScheduledExecutor())
dispatcher = Dispatcher(Executors.newSingleThreadScheduledExecutor(), runningIntegrationTests = true)
diagnosticsDispatcher = Dispatcher(Executors.newSingleThreadScheduledExecutor(), runningIntegrationTests = true)
sharedPreferencesEditor = mockk<SharedPreferences.Editor>().apply {
every { putString(any(), any()) } returns this
every { apply() } just Runs
Expand Down
Loading

0 comments on commit 67d1147

Please sign in to comment.