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

Using okhttp MockWebServer in junit calls actual url rather than mockwebserver

I am trying to use okhttp3 MockWebServer for my Junit5 test but seems it is not using MockWebServer and instead calls actual url resulting to Auth errors (401 status). Here is my test class, I am newbie to MockWebServer , is there anything wrong…
Vipin
  • 4,851
  • 3
  • 35
  • 65
0
votes
1 answer

Is there a way to guarantee coroutine execution order when using coroutineScope and launch?

I have some code I want to test that uses structured concurrency in Kotlin: suspend fun logic(): Something = coroutineScope { launch { taskOne() } launch { taskTwo() } launch { taskThree() } launch { taskFour() } …
Adel Khial
  • 345
  • 4
  • 15
0
votes
0 answers

Code block on MainCoroutineDispatcher fails to execute during instrumented test

I am working on an Android project in Android Studio (Electric Eel, 2022.1.1) and I am facing an issue where the UI update task that runs on the MainCoroutineDispatcher never gets executed. My activity makes a call to callBackend during onCreate,…
Corin
  • 2,417
  • 26
  • 23
0
votes
1 answer

java.lang.IllegalArgumentException: A metric named okhttp3.OkHttpClient.connection-pool-total-count already exists

I have upgrade HttpExecutor to v2 version recently. Now start facing duplicate metric issue while running test cases. Caused by: java.lang.IllegalArgumentException: A metric named okhttp3.OkHttpClient.connection-pool-total-count already…
Pukhraj soni
  • 1,832
  • 2
  • 17
  • 11
0
votes
0 answers

Cannot read properties when used MockWebServer

Hi I am new to the Junit Testing and am trying to test the third party call, for that I have used MockWebServer from okhttp3, the mockWebServer does the job of giving me a proper mocked response but in the class that I am trying to test has the…
0
votes
1 answer

how to use @DynamicPropertySource to set webclient url in application properties in a kotlin spring boot integration test?

I'm referencing this question posted here but trying to do the same thing in a kotlin spring boot integration test. I've modified the code to kotlin syntax like so @DynamicPropertySource fun properties(registry: DynamicPropertyRegistry) { …
0
votes
0 answers

Should Retrofit and okHttp dependencies be omitted from testing source sets in favour of mockwebserver?

I am reviewing the dependencies in my build.gradle.kts file and noticed for Retrofit and okHttp i have a bunch of dependencies in implementation, testImplementation and androidTestImplementation. Are network dependencies like Retrofit and okHttp…
mars8
  • 770
  • 1
  • 11
  • 25
0
votes
1 answer

MockWebserver Retrofit - SSLHandshakeException: connection closed

I am writing a UI test using Espresso, Dagger2, Retrofit, and MockWebserver for mocking API response. I follow this tutorial by Weidian Huang on medium -> full github source here. Iam not using SSL pinning so I remote it. But I got problem when…
Stevie
  • 401
  • 4
  • 13
0
votes
0 answers

Cannot mock Retrofit call using MockWebServer

I am trying to perform a unit test and mock a retrofit call using MockWebServer without success. When I run my test, it should run execute() block. When I test my code without CoroutineScope, it works. But I must launch that method in a coroutine…
Captain Jacky
  • 888
  • 1
  • 12
  • 26
0
votes
1 answer

Unit test a FeignClient using MockWebServer

I have a FeignClient I've developed using spring-cloud-starter-openfeign. I'd like to write a unit test using MockWebServer. How do I set up the Spring configuration for this?
Doradus
  • 938
  • 1
  • 9
  • 15
0
votes
0 answers

Using mockwebserver to test URL/URI DataHandler/DataSource

I am trying to use mockwebserver to test POSTing via a Jakarta-based activation URLDataSource's outputStream. In the jakarta.activation.DataSource, you only have "getInputStream()/getOutputStream()". The 'getOutputStream()' method internally opens a…
JWT
  • 143
  • 1
  • 6
0
votes
0 answers

java.lang.NoClassDefFoundError: kotlin/TypeCastException upon upgrade to spring-boot-starter-parent 2.7.5

I've recently upgraded my application to use spring-boo-starter 2.7.5 and it now throws the error java.lang.NoClassDefFoundError: kotlin/TypeCastException org.springframework.boot
alegria
  • 1,290
  • 14
  • 23
0
votes
0 answers

Mocking Spring WebFlux doOnSuccess()

I want to make a WebFlux reactive call to a legacy SOAP service, using WebClient. The structure of the code is as follows: AtomicReference atomicReference = new AtomicReference<>(); webClient.post() .uri(...) …
user1052610
  • 4,440
  • 13
  • 50
  • 101
0
votes
1 answer

How can I read json file in local test on Android Studio?

I am testing with MockWebServer. And I need a lot of json files for request and response data. Hard coded json values seem messy and I want to create json files instead. So, I created json files in resources(test). And I tried to read file with…
c-an
  • 3,543
  • 5
  • 35
  • 82
0
votes
1 answer

Unit Testing on Springboot WebClient with MockWebServer

After searching around the net for few days, couldn't really find the resources I need for my use case as many of it are implemented in Java. I have a service class that is calling external api, and I am trying to write unit tests on it with…
MongChangHsi
  • 103
  • 1
  • 12