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
4
votes
0 answers

Testing Instrumental (Espresso) Login using MockWebServer with Retrofit

I'm looking to create an instrumental (espresso) test from LoginActivy. I'm using Mock's for API calls, unfortunately my app keeps calling my REAL API. Below is my test code @Test public void loginSuccessTest() throws Exception { String fileName…
Duk
  • 143
  • 12
4
votes
0 answers

OkHttp3 MockWebServer with IdlingResource

Is there a standard way to combine a MockWebServer with an IdlingResource? I guess one has to implement a custom MockDispatcher but the way to go is not so evident. Has anybody tried that already?
Katerina A.
  • 1,268
  • 10
  • 24
4
votes
1 answer

Android espresso - how to use dagger2 to inject dependencies

Injecting dependencies into espresso test using dagger2 is what i would like to do. I would like a way to be able to provide dependencies for my test cases using dagger. In particular there is a MockwebServer class i want to inject with dagger. How…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
4
votes
0 answers

java.lang.NoSuchMethodError: No static method initializeInstanceForTests() MockWebServer on androidTest

I can't initialize MockWebServer on androidTest folder. I've already added this line on my gradle androidTestCompile('com.squareup.okhttp3:mockwebserver:3.6.0') { exclude group: 'com.squareup.okio', module: 'okio' exclude group:…
Tobi
  • 171
  • 8
3
votes
1 answer

How to make MockWebServer + Retrofit + Coroutines run in the same dispatcher

I'm unsuccessfully trying to use MockWebServer + Retrofit + Coroutines on my Android unit tests. During debugging, I found out that OkHttp is running on a different thread, which is why my test always fails. This is my rule to set the test…
Ygor
  • 188
  • 8
3
votes
2 answers

How do I extract param from MockWebServer when testing?

I am sending a request to a MockWebServer. I want to checkout parameters of said request for testing purposes. How can I extract it from MockWebServer?
3
votes
1 answer

Is there a way to fix the port for MockWebServer

I am trying to use MockWebServer for running my Android test cases. I am using the server.url("/") to set the path, but I was trying to figure out if there is any way to fix the port as it constantly changes.
pixelWorld
  • 329
  • 2
  • 17
3
votes
1 answer

Returning gzip responses with MockWebServer

I'm having a problem writing a test involving gzipped responses for a client that uses OkHttp. In essence what I'm doing is: @Test public void okHttp_whenResponseIsGzipped_returnsBody() throws Exception { MockWebServer mockWebServer = new…
seadowg
  • 147
  • 8
3
votes
1 answer

Running test with MockWebServer always call the failure call back (Connection Exception)

I'm running mock web server to test REST API calls, when activity launch and start the mockWebserver and execute the API call I'm getting the connection refused,using OKHTTP v-3.10.0 & Retrofit 2.3.0 ActivityTest Code: @Rule public…
Sam
  • 6,215
  • 9
  • 71
  • 90
3
votes
0 answers

Handshake failure with mockwebserver using self signed certificate

I am looking to write integration testing of OkHttpClient with a mockwebserver with ssl using an android app. I was able to use HeldCertificate and HandshakeCertificates to achieve this, but I am interested in using self signed certs. While trying…
Simpson
  • 292
  • 3
  • 13
3
votes
3 answers

Timeout while using MockWebServer?

I try to use MockWebServer to the various responses to my API. I have made a simple example just to try that what I would like to do is a working method. Isn't the mockWebServer meant to 'mock' the endpoint of my http connections? Like a real…
Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222
3
votes
0 answers

Retrofit2 unit testing, MockWebServer

I would like to test my Rest services build under Retrofit2. I don't want to mock all responses individually, but I would like to mock the entire web server. I found that it's possible with MockServer. But I am not able to work with it. My…
Maurice
  • 2,129
  • 2
  • 25
  • 33
3
votes
0 answers

Mocking web server for development

I'm curious if anyone uses a tool like MockWebServer for general development? I've used MockWebServer to run instrumentation tests against. In a testing situation it's very easy to use because you can enqueue the response you want per test method. I…
neonDion
  • 2,278
  • 2
  • 20
  • 39
2
votes
0 answers

Get MockWebServer port into the Spring container with SpringBootTest

I have a Spring Boot + WebFlux application with the following structure: A controller ControllerA that uses a service ServiceA. ServiceA uses a WebClient to call a remote microservice microservice A. The URL of the endpoint in microservice A is…
wujek
  • 10,112
  • 12
  • 52
  • 88
2
votes
2 answers

Maven dependencies wrong version for okhttp3 mockwebserver

I am trying to use okhttp3.mockwebserver with my Spring boot project and I find out that okhttp3:mockwebserver:jar:3.14.9 is included instead of 4.9.1. I have created small 'mock' projects to reproduce the issue I have in my prod. The project is…
mkarasik
  • 146
  • 11