-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add unit tests to ParselyAPIConnection
and minor refactor of it
#81
Conversation
Just above we clear `eventQueue` and purge locally stored events. There's no need to check the size of the queues.
This way, we don't have to check for nullability of the tracker. Also using `ParselyAPIConnection` without first initialising `ParselyTracker` doesn't seem to make any use case, so I think it's a save change.
BREAKING CHANGE: `ParselyAPIConnection` is no longer accessible for library consumers. This is a deliberate design change. The `ParselyAPIConnection` on its own doesn't provide value for library consumers: it doesn't do anything domain-specific for Parsely, except purging queue after successful events. I think it's completely save to make it accessible only from the library.
No need for this field to be `public`
Every time SDK purges in-memory events queue, it purges stored queue and vice-versa. The extraction of method asserts this behaviour and increases readability
To unit test HTTP communication logic, framework agnostic.
Previously, the `ParselyAPIConnection` task was not finishing execution before the test finished. Only because the task's `onBackground` was fast, the test was passing. To remove this flakiness, the introduced change uses LooperMode.Mode.PAUSED to wait for AsyncTask execution to finish, before running assertions.
See ab4fe3a for details.
The `object` state persisted between tests, what influenced results depending on order of tests execution.
There's no need to return `HttpURLConnection`. This change simplifies implementation.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #81 +/- ##
===========================================
+ Coverage 20.44% 32.95% +12.51%
===========================================
Files 5 5
Lines 362 355 -7
Branches 58 56 -2
===========================================
+ Hits 74 117 +43
+ Misses 278 225 -53
- Partials 10 13 +3
☔ View full report in Codecov by Sentry. |
} | ||
|
||
companion object { | ||
val pixelPayload = """ |
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.
The auto-format doesn't work here :/ I didn't format this by hand because it looks ok (readable) and I'm concerned about future edits of this field (and a need to format again by hand).
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.
Suggestion (💡): I actually wanted to suggest using test/resources/pixel_payload.json
instead. Wdyt? 🤔
private class FakeTracker : ParselyTracker( | ||
"siteId", 10, ApplicationProvider.getApplicationContext() |
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.
Initially, I wanted to introduce a package private interface (QueueManager
?) but due to limitations of Java (interface methods must be public
) I couldn't do it. Hence, the fake class extends the whole ParselyTracker
.
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.
Praise (❤️): Actually, I like what you did here, so 👍 !
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.
👋 @wzieba !
I have reviewed and tested this PR as per the instructions, everything works as expected, great job on yet another test added! 🌟 🧪 🌟
I have left few a couple of suggestions (💡) for you to consider. I am going to approve this PR anyway, since none is blocking. I am NOT going to merge this PR yet to give you some time to apply any of my suggestions. However, feel free to ignore them and merge the PR yourself.
parsely/src/main/java/com/parsely/parselyandroid/ParselyAPIConnection.java
Show resolved
Hide resolved
parsely/src/test/java/com/parsely/parselyandroid/ParselyAPIConnectionTest.kt
Show resolved
Hide resolved
} | ||
|
||
companion object { | ||
val pixelPayload = """ |
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.
Suggestion (💡): I actually wanted to suggest using test/resources/pixel_payload.json
instead. Wdyt? 🤔
private class FakeTracker : ParselyTracker( | ||
"siteId", 10, ApplicationProvider.getApplicationContext() |
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.
Praise (❤️): Actually, I like what you did here, so 👍 !
parsely/src/test/java/com/parsely/parselyandroid/ParselyAPIConnectionTest.kt
Outdated
Show resolved
Hide resolved
Thanks @ParaskP7 for the review! I've addressed your suggestions 👍 |
Awesome, thanks @wzieba , everything LGTM! 🙇 ❤️ 🚀 |
Description
This PR adds unit tests for
ParselyAPIConnection
and adds some minor refactor to it.How to test
Review and running unit tests should be just fine. Due to async nature of, well,
AsyncTask
, you can also verify that each test execution waited forAsyncTask
to finish. You should seePixel request success
orPixel request exception
at the end of test logs.