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

Espresso Mock Web Server not waiting OkHttp Idling Resource with Dagger Hilt

I am trying to write UI test for my Fragments with Espresso and MockWebServer. I am using OkHttp Idling Resource to tell Espresso to wait for the API calls to complete. But somehow, sometimes my tests are working but sometimes not, because Espresso…
ysfcyln
  • 2,857
  • 6
  • 34
  • 61
10
votes
2 answers

MockWebServer: java.lang.NoSuchMethodError

Trying MockWebServer for the first time on a Groovy/Spring project that uses Spock for unit testing. I added MockWebServer dependencies as directed (I had to add the second line myself to avoid errors, but it's not…
user3303372
  • 761
  • 1
  • 10
  • 21
9
votes
1 answer

MockWebServer with Retrofit and Dagger

I tried to implement instrumentation test for my android project. In my main project, I used dagger and retrofit and I provide the retrofit from my Module. This is my Module that provide retrofit: @Module public class NetModule { @Provides …
Tobi
  • 171
  • 8
9
votes
3 answers

Moshi Retrofit error: "Expected a string but was BEGIN_OBJECT"

I built my Retrofit instance like this: Retrofit retrofit = new Retrofit.Builder() .baseUrl(server.url("/")) .addConverterFactory(MoshiConverterFactory.create(moshi)) .build(); Then I am calling my MockWebServer…
IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
8
votes
0 answers

Mockwebserver shutdown failed

I am getting this error java.io.ioexception gave up waiting for executor to shut down when I do mockwebserver.shutdown(). I can see in the debug trace that the server has few active threads which is causing the error. Is there a way to check and…
Daisy Modi
  • 93
  • 3
8
votes
1 answer

MockwebServer doesn't mock http call

I recently discovered MockWebServer library and I try to use it in my project with Junit and mockito. I have this test method: @Test public void testGetUsers() throws Exception { MockWebServer server = new…
Brahim.Bou
  • 125
  • 1
  • 5
8
votes
1 answer

How to make MockWebServer work?

I am developing an app using the MVP architecture. I am trying to test the Interactors of my app using MockWebServer. Well, I have this test: @RunWith(RobolectricTestRunner::class) @Config(constants = BuildConfig::class, manifest =…
Leandro Borges Ferreira
  • 12,422
  • 10
  • 53
  • 73
7
votes
2 answers

Testing suspending functions for exception with JUnit5 assertThrows and MockWebServer

How can we test a suspending function with MockWebServer that supposed to throw exception? fun `Given Server down, should return 500 error`()= testCoroutineScope.runBlockingTest { // GIVEN …
Thracian
  • 43,021
  • 16
  • 133
  • 222
7
votes
1 answer

Suspending function test with MockWebServer

I'm testing api that returns result using suspending function with MockWebServer, but it does not work with runBlockingTest, testCoroutineDispatcher, testCorounieScope unless a launch builder is used, why? abstract class AbstractPostApiTest { …
Thracian
  • 43,021
  • 16
  • 133
  • 222
7
votes
0 answers

NoSuchFieldError: Companion when using MockWebServer in kotlin only module

I have a modularised project, where the api layer is separated into its own module. As this has no dependency on the Android SDK, I have made it a kotlin only module. This has the kotlin jvm plugin as shown below in the build file. This results in a…
Vin Norman
  • 2,749
  • 1
  • 22
  • 33
7
votes
4 answers

Mockwebserver in gradle build throwing error

This entry in my gradle file : androidTestCompile ('com.squareup.okhttp:mockwebserver:2.7.0') is throwing error: Warning:Conflict with dependency 'com.squareup.okio:okio'. Resolved versions for app (1.8.0) and test app (1.6.0) differ. See…
Mike6679
  • 5,547
  • 19
  • 63
  • 108
7
votes
4 answers

Using MockWebServer with Robolectric

I'm trying to unit test some API calls using MockWebServer and Robolectric. My test class is annotated with: @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, sdk = 23) However when trying to build the Retrofit…
user_4685247
  • 2,878
  • 2
  • 17
  • 43
7
votes
2 answers

How can I use OkHttpClient MockWebSever to return an image/byte[]?

I'm working on an android library project, where I need to download an PNG image from a REST service, transform it into a Bitmap and return it to the app(s) using this library. So, we have a REST webservice that returns the bytes of a png image.…
ASP
  • 773
  • 1
  • 8
  • 22
6
votes
1 answer

Mock server requests Android Espresso UI Testing

I am using Espresso to write UI tests for my Android application and would like to mock http requests using MockWebServer. I need to mock authentication responses and sign in the user before the tests are run. Is there a way make the app use…
yinjia
  • 804
  • 2
  • 10
  • 20
6
votes
1 answer

How to test service calls using mockwebserver that contains redirection?

I am using mockwebserver to mock request and response for my android app. I am testing a login feature which goes through a series of 4 service calls. Get access token Re-direct Get user info (different base url) Get some other stuff (original…
AccTest
  • 313
  • 3
  • 11
1
2
3
10 11