question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decouple Chucker from Android

See original GitHub issue

⚠️ Is your feature request related to a problem? Please describe

I don’t like that ChuckerInterceptor is coupled with the Android framework. It restricts it and makes testing harder. The need for doing that in tests makes me sad.

https://github.com/ChuckerTeam/chucker/blob/d919874d602733da1c90ceea1a658d69ea242036/library/src/test/java/com/chuckerteam/chucker/ChuckerInterceptorDelegate.kt#L26-L33

💡 Describe the solution you’d like

Right now this is a primary constructor.

https://github.com/ChuckerTeam/chucker/blob/d919874d602733da1c90ceea1a658d69ea242036/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt#L39-L45

I’d like to change it and introduce some internal interfaces for i.e. providing resource strings or collecting requests/responses. These interfaces would have implementations based on Context that would be used from a secondary constructor that accepts an instance of Context.

📊 Describe alternatives you’ve considered

It does not solve the whole problem but some testing issues could be solved by running instrumented tests. I don’t think it should be done as the only step and I’d like to make the main proposal happen. However, it would be also good to run instrumented tests with the real scenario setup (I can create a separate issue for this).

📄 Additional context

This is for Chucker 4.x.

🙋 Do you want to develop this feature yourself?

  • Yes
  • No

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cortinicocommented, Jul 25, 2020

Having interfaces would enable to test fake implementations against real ones and using former in tests of ChuckerInterceptor. If in your opinion it does not bring much value I don’t have any real need to pursue this. 😃

I think we should really work in this direction.

Imho the title of this issue is a bit misleading as “Decouple Chucker from Android” is really out of the scope of this library (we provide a debugging tool for Android, so we need to depend on the framework).

From my point of view we should evolve our API (for 4.x in this direction):

  1. Keep on having a ChuckerInterceptor(Context) constructor (i.e. our primary constructor with default values). Applying our library should as easy as that. It’s reasonable to ask for a Context to our users as we’re showing UI/Notifications, etc.
  2. Have all the Android related code inside the ChuckerCollector. That’s going to be the connection point between our library and the Android framework
  3. Ideally extracting ChuckerCollector to an interface to better define the interaction between collector/interceptor and for better testability
  4. Ideally the ChuckerInterceptor should delegate all the implementation to a pure java class that interacts with this extracted interface.

This makes code for us easier to maintain and test.

As a side note, for the sake of testing we should probably work on extracting all the processResponseBody, processRequest methods inside the ChuckerInterceptor to separate classes and test them in isolation. This is something we can start doing today. It won’t fix the overall issue as you still have to mock a ChuckerCollector that needs a Context, but we can keep it as an iterative process and further improve once we extract an interface out of it.

1reaction
MiSikoracommented, Jul 21, 2020

Well, yes. My main motivation are tests. However, not for tests sake but for making the code more testable. Having interfaces would enable to test fake implementations against real ones and using former in tests of ChuckerInterceptor. If in your opinion it does not bring much value I don’t have any real need to pursue this. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChuckerTeam/chucker: An HTTP inspector for ... - GitHub
Chucker simplifies the inspection of HTTP(S) requests/responses fired by your Android App. Chucker works as an OkHttp Interceptor persisting all those ...
Read more >
Decoupling Binding. Make Android apps much, much simpler
An Activity or Fragment is just the glue for the Android system, the View (layouts), and ViewModels; Refactor all your UI related code...
Read more >
Chucker: an OkHttp Interceptor that levels up your Android ...
It is possible that you find an error in your Android app API calls when the phone is not connected to the Android...
Read more >
Make your Android application rock SOLID — Interfaces
Think about interfaces and why we use them. We tend to use them in order to define protocols, communication, decoupling (we'll talk more...
Read more >
Android and iOS View/Logic Decoupling With Examples
To make our app code better structured, one would separate the logic from the view — e.g. Activity (in Android) and ViewController (in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found