Questions tagged [mockwebserver]

A library for testing HTTP and HTTPS clients.

This library makes it possible to write fast, reliable unit tests for HTTP clients. Like object mocking frameworks, it allows you to script mock responses, exercise them, and then review the recorded requests.

Link: https://code.google.com/p/mockwebserver/

157 questions
1
vote
0 answers

How can I mock Repository when it uses retrofit2 and room in it?

I am trying to write test code for a ViewModel. and the ViewModel uses this repository, so I'd like to mock it. class ServiceRepository @Inject constructor( private val service: MyService, private val dao: MyDao ) { suspend…
c-an
  • 3,543
  • 5
  • 35
  • 82
1
vote
1 answer

How can I enable OkHttp's MockWebServer logging?

I was using an old version of MockWebServer 3.14.9 in my Android project and I could see its logs in the logcat when running my UI Tests. After updating to the latest 4.10.0 I can't see any MockWebServer logs for requests and responses. It appears…
Just The Highlights
  • 1,555
  • 19
  • 31
1
vote
1 answer

Imitate webserver for tests with Jest

I have a bit of a weird question: I have a program for scraping data from webpages (just the actual HTML pages, not API responses). I need to write end-to-end tests for this program with the Jest library. In order to test the functionality…
Abraham
  • 185
  • 1
  • 10
1
vote
2 answers

Unresolved Reference: mockwebserver

I'm writing a test suite with mockwebserver. I entered all of the dependencies from the official github page. Every time I try to run the test I receive Unresolved reference: mockwebserver There's no option to import. The lettering isn't red on…
petestmart
  • 500
  • 11
  • 27
1
vote
0 answers

Android: Could not resolve junit:junit:{strictly 4.12}

I am getting this error and I'm not able to fix it. Required by: project :app > Cannot find a version of 'junit:junit' that satisfies the version constraints: Dependency path 'app1-android-new:app:unspecified' -->…
1
vote
1 answer

java.io.IOException: unexpected end of stream on http://localhost:33339/

I am using retrofit and okhttp3.mockwebserver.MockWebServer for Android Test. I am getting this error while running a test. Gradle: androidTestImplementation "com.squareup.okhttp3:mockwebserver:3.14.9" def retrofit_version = "2.9.0" …
snehal
  • 181
  • 1
  • 10
1
vote
0 answers

MockWebServer returning Json but restTemplate.exchange always maps to null

I am writing an integration test for a java component that calls some local service (in port 8888). I am able to intercept the call by passing the port as an argument to the MockWebServer, like this: MockWebServer server= new MockWebServer(); …
carlos palma
  • 722
  • 3
  • 12
  • 29
1
vote
2 answers

java.lang.NoSuchMethodError: okhttp3.internal.Internal.initializeInstanceForTests in Android Studio 4.1

I just upgraded Android Studio 4.1 and got all the tests related to mock webserver failed in IDE but not in terminal. It passed fine before I upgraded to 4.1. My Okhttp and mockwebserver version is 4.7.2 TestCase.kt class RepositoryTest :…
1
vote
2 answers

java.lang.IllegalArgumentException: Log tag "okhttp3.mockwebserver.MockWebServer" exceeds limit of 23 characters

Some points to clarify that this is not a duplicate question as someone suggested: This is a "runtime crash" caused by long log tag name. i.e. okhttp3.mockwebserver.MockWebServer, this is not an IDE lint error. This crash is caused by a third party…
shizhen
  • 12,251
  • 9
  • 52
  • 88
1
vote
0 answers

MockWebServer Android test fails on CI

I have written a unit test with MockWebServer to catch ConnectionExceptions thrown by Retrofit and convert them to a domain level error. @Test fun `check that factory returns no internet error for ConnectException when no internet`() { val…
Stelian Morariu
  • 505
  • 7
  • 16
1
vote
2 answers

How to provide test retrofit url with Hilt

In my application I started to use Hilt as DI. So I create a class to provide retrofit in in my repository like this @InstallIn(ApplicationComponent::class) object RetrofitModule { var baseUrl = "https://my.fancy.api" @Singleton …
dudi
  • 5,523
  • 4
  • 28
  • 57
1
vote
1 answer

WebTestClient with MockWebServer hangs

I have a spring boot application that exposes a rest api using "spring-boot-starter-webflux". My application calls other rest services when one of my endpoint is called. I'm trying to make an integration test using WebTestClient to mimic the client…
1
vote
0 answers

How to mock two APIs with MockWebServer Android test cases

I am performing instrumentation testing, in that I am invoking one of the activities which call 2 APIs when activity is created. Now I want to write instrumentation test cases for this activity, where I have to mock the API response with…
1
vote
1 answer

How to test screens which requires authorization? Espresso + MockWebServer

I am creating UI tests. In order not to interact with the real server, I use MockWebServer. My goal is to emulate various server responses and see how the program as a whole will respond to them. At the moment, I don’t understand how to open screens…
1
vote
0 answers

Android JUnit testing api

I have a function here which gets the list of Posts from JSONplaceholder api. If want to implement testing on this function how do I do it and what will I need, Mockito, JUnit override fun getAllPosts(): Flowable> { return…
BRDroid
  • 3,920
  • 8
  • 65
  • 143