Skip to content

refactor: remove reflection on unit tests #263

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

Merged
merged 5 commits into from
Apr 10, 2025

Conversation

polbins
Copy link
Contributor

@polbins polbins commented Apr 9, 2025

Summary

Enable setting of your own dispatchers for tests, added factory methods for creating fakes, and cleaned up a bunch of tests as well.

It's easier to review just the last two commits: https://github.com/amplitude/Amplitude-Kotlin/pull/263/files/cc5de2659b7c5d4abc26a72231e624a8dccb39c4..2e492d92336e6133532741da93744dcd24708cb3#diff-9b0abba662a8a3d0d290c1970d3ea84a56e092ad06e3e5445f391ec51ff83e9eR82-R85

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

@polbins polbins changed the title refactor/test: remove reflection on unit tests refactor: remove reflection on unit tests Apr 9, 2025
@polbins polbins force-pushed the AMP-128374/remove-reflection-on-unit-tests branch from 9b8d04a to 2e492d9 Compare April 9, 2025 21:04
@@ -41,7 +41,7 @@ import java.util.concurrent.Executors
* This is the SDK instance class that contains all of the SDK functionality.<br><br>
* Many of the SDK functions return the SDK instance back, allowing you to chain multiple methods calls together.
*/
open class Amplitude internal constructor(
open class Amplitude(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to open this up for testability

@polbins polbins marked this pull request as ready for review April 9, 2025 21:23
@polbins polbins requested a review from igor-amp April 9, 2025 21:23
Comment on lines +82 to +85
eventsList.forEach {
delay(BACK_OFF)
eventPipeline.put(it)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like to add this, but the current response handler integration tests are made in such a way that requires adding delays to control the flow of the test. This requires a lot more effort to fix, so it might be good to revisit when we're dealing with InMemoryStorage tasks.

import kotlinx.coroutines.test.TestScope

@OptIn(ExperimentalCoroutinesApi::class)
class FakeAmplitude(
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need fake? Can't we use spy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can use Spy! But Fakes are easier to use (no need for a library) and less boilerplate too, so usually fakes are preferred for tests

@polbins polbins force-pushed the AMP-128374/remove-reflection-on-unit-tests branch from b2e1897 to 8ddb1fe Compare April 10, 2025 18:09
@polbins polbins merged commit ddbab47 into main Apr 10, 2025
4 checks passed
@polbins polbins deleted the AMP-128374/remove-reflection-on-unit-tests branch April 10, 2025 18:16
Copy link

🎉 This PR is included in version 1.20.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

github-actions bot commented May 2, 2025

🎉 This PR is included in version 1.20.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants