-
Notifications
You must be signed in to change notification settings - Fork 663
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
Setup AnalyticEventCallbackRule for DefaultEventReporterTest #10575
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to share the test rule for both DefaultEventReporterTest
(unit test) and other analytics tests (android test). If I place the rule to somewhere they all can access like payments-core-testing
, then AnalyticEventCallback
can not be accessed by the rule. It seems that I can only write two rules for the test separately.
events.expectNoEvents() | ||
events.ensureAllEventsConsumed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure which one is better. Or should we use both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the correct one.
Diffuse output:
APK
|
@@ -950,7 +933,7 @@ class DefaultEventReporterTest { | |||
simulateSuccessfulSetup(linkMode = null, googlePayReady = false) | |||
} | |||
|
|||
analyticEventCallbackProvider.set(null) | |||
analyticEventCallbackRule.setCallback(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the nulling it out happen automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the default is to receive the event. The AnalyticEventCallbackRule
will set the turbine as the default callback at the beginning of the tests and null them after finishing. This setting is reasonable to me because this reduce boilerplate code when testing all nine kinds of events.
analyticEventCall.add(event) | ||
} | ||
|
||
fun setCallback(callback: AnalyticEventCallback?) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the use case for this? It seems kinda confusing that it can be set in two different ways?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for setting non default callbacks, e.g. null callback or throwing errors. I think wrapping this as a function looks more like the callback builder in the production code. I can remove this setter and make the callback member variable public if that is better.
It seems kinda confusing that it can be set in two different ways?
I think there is only one setter exposed for this class?
Summary
Use a
TestWatcher
to wrap up the callback provider initialization and the turbine clean up.Motivation
To prevent duplicate callback initializing when adding more tests
Testing