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
0
votes
1 answer

Use MockWebServer without extending Application

I want to use MockWebServer to mock the response of requests in my UI tests. Every getting-started-guide or tutorial I found place the url in a custom MyApp extends Application class and make it available by public String getApiUrl {return…
Gerke
  • 926
  • 1
  • 10
  • 20
0
votes
1 answer

Mockwebserver takeRequest() method infinite execution

I added a request using enque (), but using the debugger, you can see that when you call takeRequest inside it, requestQueue = 0, which means that there is no request, after which takeRequest () waits for a request indefinitely. What could be the…
SadRat
  • 3
  • 1
0
votes
1 answer

How to only test the Retrofit request param in MockWebServer without actually execute the request?

I know it's possible to test Retrofit request & response with MockWebServer, like this: interface AppApi { @GET("/time/") suspend fun time(): TimeResponse } ... class CoinBaseApiClientTest { private val mockWebServer =…
anticafe
  • 6,816
  • 9
  • 43
  • 74
0
votes
1 answer

MockWebServer not throwing custom exception retrofit

I'm implementing mockWebServer and it works for the 200 calls, but when I try to get an exception I'm getting this exception : Exception in thread "OkHttp Dispatcher" java.lang.Error: com.myproject.something.errors.MyException$ServerUnavailable …
StuartDTO
  • 783
  • 7
  • 26
  • 72
0
votes
1 answer

RxJava blockingFirst/Single returns wrong exception in JUnit 5 Retrofit Test

Test below is expected to return HttpException but it returns RuntimeException instead. @Test fun `Server down returns 500 error`() { mockWebServer.enqueue(MockResponse().setResponseCode(500)) val exception: Exception = …
Thracian
  • 43,021
  • 16
  • 133
  • 222
0
votes
1 answer

Is it possible to return http response code = 200 exactly for my test?

I start my instrumental test to check my activity. When press button on Activity then call http request. So I test click @Test fun click_checkRequest() { mockServer.enqueue( MockResponse() …
Alexei
  • 14,350
  • 37
  • 121
  • 240
0
votes
1 answer

How to deserialize request multipart body from string

I have a string representing a multipart/form-data body of a request and I want to parse it in order to write a unit test with assertions for its values. I'm using spring MultipartBodyBuilder for building the body of the request. Then I want to have…
Yaniv
  • 144
  • 1
  • 11
0
votes
0 answers

Mockwebserver and OkHttpIdlingResrouce Connect Exception

I am writing instrumentation tests using Square's MockWebServer to mock server responses and OkHttpIdlingResource to wait for OkHttp to finish work until the remaining test steps continue. I am also using a MockWebServer dispatcher so that I can…
neonDion
  • 2,278
  • 2
  • 20
  • 39
0
votes
1 answer

How to start check during long operation (load data from network)

Adnroid studio 3.3. In my app I use Retrofit to do http request. Also I use MockWebServer to return stub response. On activity when I click button I start async http request (by Retrofit) and wait callback method to return response. Here Espresso's…
Alexei
  • 14,350
  • 37
  • 121
  • 240
0
votes
1 answer

MockWebServer - Value counts differ; Expected: 1, Actual: 0

Logcat error: Feb 07, 2019 10:52:49 AM okhttp3.mockwebserver.MockWebServer$2 execute INFO: MockWebServer[54845] starting to accept connections [size=9333 text=[\n {\n "userId": 1,\n "id": 1,\n "title": "quidem molesti…] Feb 07, 2019…
Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
0
votes
1 answer

The Mono.flatMap is not working while mocking the response using MockWebServer

Making an HTTP call using WebClient, from the Mono output I want to do some logic, for which I'm using flatMap method. Mono authResponseMono = webClient.post().syncBody(requestBody) .retrieve() …
Pranav
  • 952
  • 9
  • 20
0
votes
1 answer

Mock Server for interval Flux?

I attempt to write a test function for a service that consumes an interval Flux from another service, created like Flux.interval(Duration.ofSeconds(1)).map( ... ). If seen Support of MockRestServiceServer for WebClient, which is exactly what I would…
PeMa
  • 1,559
  • 18
  • 44
0
votes
1 answer

Android Espresso MockWebserver setting cookies

I tried to set cookies in my Android Instrumentationtest like this: @Override protected MockResponse onDispatch(RecordedRequest request) { if (request.getPath().startsWith("/?loginkulcs=")) { MockResponse response = new MockResponse() …
zamek 42
  • 793
  • 1
  • 9
  • 15
0
votes
1 answer

MockWebServer not finish

I used MockWebServer like below code. But MockWebServer not finish. The test is infinitely progressing. What I missed? Result: Jul 02, 2018 7:30:59 PM okhttp3.mockwebserver.MockWebServer$2 execute 정보: MockWebServer[49728] starting to accept…
illusionJJ
  • 419
  • 1
  • 7
  • 23
0
votes
0 answers

OkHttp MockWebServer fails to accept connections on new instance

I'm using OkHttp MockWebServer to mock the server responses. I have implemented two tests classes, the first one contains two tests and the second one, one test. The first class works fine, but for the second class, there is an error because the…
Maurice
  • 2,129
  • 2
  • 25
  • 33
1 2 3
10
11