-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fixed LeakCanary #5784
Fixed LeakCanary #5784
Conversation
7368df9
to
e716552
Compare
@@ -0,0 +1,5 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<resources> | |||
<string name="leak_canary_test_class_name" translatable="false">assertk.Assert</string> |
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.
Could you explain how this fixes things? Might be worth a comment.
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 enables LeakCanary. It was disabled with this message: LeakCanary is currently disabled: test class org.junit.Test was found in classpath
and according to https://square.github.io/leakcanary/changelog/#api-breaking-bettering-changes this is how we need to fix it.
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've added a comment.
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.
Right. Not sure I get why we're using assertk.Assert
as the test class to detect though? We don't use assertk as far as I'm aware.
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.
By default, LeakCanary will look for the org.junit.Test class in your classpath and if found, will disable itself to avoid running in tests. However, some apps may ship JUnit in their debug classpaths (for example, when using OkHttp's MockWebServer) so we offer a way to customise the class that is used to determine that the app is running in a test environment.
My understanding is that by default it looks for org.junit.Test and in our case it was found and LeakCanary was disabled.
With this line, it will look for assertk.Assert
that does not exist so LeakCanary will be enabled.
That's how I understand it but the documentation is poor and I'm not the only one complaining about it.
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.
With this line, it will look for
assertk.Assert
that does not exist so LeakCanary will be enabled.
Right. But that will mean it also runs during tests right? My interpretation of those docs is that we should set leak_canary_test_class_name
to a class that will only be present in tests (which would be the original intention of org.junit.Test
.
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.
Right, I used androidx.test.ext.junit.runners.AndroidJUnit4
instead.
30d43be
to
3d9e06c
Compare
Closes #5782
Why is this the best possible solution? Were any other approaches considered?
Nothing to discuss here. I've just fixed LeakCanary so that it works well for us.
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
It doesn't require testing.
Do we need any specific form for testing your changes? If so, please attach one.
No.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No.
Before submitting this PR, please make sure you have:
./gradlew checkAll
and confirmed all checks still pass OR confirm CircleCI build passes and run./gradlew connectedDebugAndroidTest
locally.