Skip to content

Add backend integration tests and test product entitlement mapping endpoint#979

Merged
tonidero merged 6 commits into
update-product-entitlement-mapping-request-formatfrom
toniricodiez/sdk-3015-integration-tests-android-get
Apr 26, 2023
Merged

Add backend integration tests and test product entitlement mapping endpoint#979
tonidero merged 6 commits into
update-product-entitlement-mapping-request-formatfrom
toniricodiez/sdk-3015-integration-tests-android-get

Conversation

@tonidero

@tonidero tonidero commented Apr 21, 2023

Copy link
Copy Markdown
Contributor

Description

SDK-3015

This PR adds backend integration tests. These are setup as unit tests in the common module.

I thought about adding these as instrumentation tests, but that increases the complexity and runtime of these tests, and we can relatively simply run them as unit tests in the JVM.

@tonidero tonidero added the test label Apr 21, 2023
sharedPreferences = mockk<SharedPreferences>().apply {
every { getString(any(), any()) } answers { secondArg() as String? }
every { edit() } returns sharedPreferencesEditor
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note how I've had to mock the appConfig and the sharedPreferences. Both of those require a Context which is not available during unit tests.

Comment thread common/build.gradle
include "com/revenuecat/purchases/backend_integration_tests/**"
} else {
exclude "com/revenuecat/purchases/backend_integration_tests/**"
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This makes it so, when we run unit tests normally, we won't be executing these integration tests. Only if we add the RUN_INTEGRATION_TESTS property we will run those tests exclusively.

class BackendIntegrationTest {

companion object {
private val TIMEOUT = 5.seconds

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note the timeout here is a bit high... But I got a couple of failures with 2 seconds, not sure if there was a reason for it to be so slow...

Comment thread .circleci/config.yml
- test
- detekt
- assemble-sample-app
- run-backend-integration-tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it should be fine to run these on all commits... They shouldn't take too long.

@tonidero tonidero requested a review from a team April 21, 2023 12:25
@tonidero tonidero marked this pull request as ready for review April 21, 2023 12:25
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class LoadShedderBackendIntegrationTest: BaseBackendIntegrationTest() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The way I structured this right now, these and production backend integration tests live in the same place and are run at the same time. They are pretty fast though so I think that's fine. Lmk if you would prefer to run them separately.

Comment thread fastlane/Fastfile
paths_of_files_to_update: [constants_path]
)
replace_text_in_files(
previous_text: 'LOAD_SHEDDER_API_KEY',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be LOAD_SHEDDER_REVENUECAT_API_KEY?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So I used LOAD_SHEDDER_API_KEY in the Constants.kt file to avoid accidentally changing it in the previous replace, where we replace REVENUECAT_API_KEY. We could use patterns to avoid that problem though I guess, but this works for now.

block(latch)
latch.await(TIMEOUT.inWholeSeconds, TimeUnit.SECONDS)
assertThat(latch.count).isEqualTo(0)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I love this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think this could be useful for many other tests as well. For now I'm just using it here but we could consider it moving to the test-utils module and use it in many other tests.

@tonidero tonidero merged this pull request into update-product-entitlement-mapping-request-format Apr 26, 2023
@tonidero tonidero deleted the toniricodiez/sdk-3015-integration-tests-android-get branch April 26, 2023 08:55
tonidero added a commit that referenced this pull request May 5, 2023
…dpoint (#988)

### Description
SDK-3015

This PR adds backend integration tests. These are setup as unit tests in
the `common` module.

I thought about adding these as instrumentation tests, but that
increases the complexity and runtime of these tests, and we can
relatively simply run them as unit tests in the JVM.

This is an almost duplicate of #979. Those changes were lost after being
merged to the wrong branch. Only change after that is fixing the load
shedder test now that we are actually requesting to the load shedder
after some backend changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants