Skip to content
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

Using Okhttp with checker in unit-tests #977

Open
abbasiehsan1991 opened this issue Feb 27, 2023 · 3 comments
Open

Using Okhttp with checker in unit-tests #977

abbasiehsan1991 opened this issue Feb 27, 2023 · 3 comments

Comments

@abbasiehsan1991
Copy link

abbasiehsan1991 commented Feb 27, 2023

✍️ Describe the bug

I'm using Dagger for injection and in some places in the unit tests I used injection too.
By adding the chucker into my OKHttp some of my unit tests start to fail because of the checker. I don't have different component for tests which is recommended as I understand, But I'm wondering the reason that chucker make an issue with tests in this case, and maybe a solution for it because changing into my current dagger flow is really hard and I'm trying to avoid it for now.

💣 Steps to reproduce

  1. Provide OkHttp with Dagger
  2. Add Chucker as an interceptor into the OkHttp
  3. use the OkHttp into unit-test test components(Module that providing the OkHttp is same as production DI)
  4. Test Components will not generate because they have an issue providing chucker (This is only in test components not in production components)
  5. App builds successfully and chucker works, But tests fail

🔧 Expected behavior

Why Chucker has a problem with unit tests, and a solution to fix it.

📱 Tech info

  • OS: Android
  • Chucker version: 3.5.2
@cortinico
Copy link
Member

I don't have different component for tests which is recommended as I understand

You should not use Chucker in unit tests as it will attempt to show UI components which most likely you won't have in your test environment.

As you said, you should have a more streamlined OkHTTP client for tests only that doesn't contain Chucker

@erawhctim
Copy link

It's not chucker's responsibility to know the context in which it's being executed (i.e. in your unit test); it's your app's responsibility to ensure that Chucker isn't installed/configured as part of your unit test suite

@cortinico
Copy link
Member

It's not chucker's responsibility to know the context in which it's being executed (i.e. in your unit test); it's your app's responsibility to ensure that Chucker isn't installed/configured as part of your unit test suite

Chucker works under the assumption that there is an Android Context where UI can be rendered. You're right that we could refactor this, but that's how the library works currently.

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

No branches or pull requests

3 participants