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

Mock 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
0
votes
2 answers

MockWebServer Connection refused: no further information

Using MockWebServer with the following dependencies: testImplementation("com.squareup.okhttp3:mockwebserver") And the following test class: class MockWebServerTest() { private val mockWebServer = MockWebServer() private val client =…
Sjoerd222888
  • 3,228
  • 3
  • 31
  • 64
0
votes
2 answers

Unit testing on local file throws java.io.FileNotFoundException in macbook

response = File("src\\test\\java\\com\\resources\\products\\response.json").bufferedReader() .use { it.readText() } I have this line of code for mocking response and it is working fine on pc but throws not found on macbook? Any…
dgncn
  • 15
  • 1
  • 9
0
votes
0 answers

JUnit WebClient ExchangeToMono test using MockWebServer

I am trying to do code coverage for my below WebClient implementation. I was able to come up with a test case, but for some reasons it's not covering ExchangeToMono part wherein I am calling a private method. It's covering the other parts leaving…
Jestino Sam
  • 526
  • 2
  • 12
  • 31
0
votes
1 answer

RetryInterceptor testing with mockwebserver cancels connection

I have the following setup: spring boot application with an okHttp3 client. I have a custom retry mechanism that needs to retry the call in every situation for a limited amount of times. The interceptor is as follows: spring boot: 2.5.5 okhttp:…
BarbetNL
  • 408
  • 2
  • 16
0
votes
1 answer

Mocking nested retrofit api calls using MockWebServer

I am writing a junit test using okhttp3.mockwebserver for a retrofit2 rest api. The trimmed down api looks like this: public interface MyApi{ @POST("/api/get-orders") retrofit2.Response> getOrders(); @POST("/api/cxl-order") …
CaptainHastings
  • 1,557
  • 1
  • 15
  • 32
0
votes
1 answer

jakewharton Espresso Idling Resource won't import

I'm writing tests using okhttp3, mockwebserver, and retrofit2 in Android/Kotlin. Everything I look up tells me to use the jakewharton idling resource, but it will not import into my project. I got the info straight from Jake Wharton's…
petestmart
  • 500
  • 11
  • 27
0
votes
1 answer

An annotation argument must be a compile-time constant @RunWith(AndroidJUnit4::class)

My test suite won't run and it appears to be the @RunWith(AndroidJUnit4::class). I was following along with a tutorial, so I'm not 100% sure what that part does, or what this means. The @RunWith(AndroidJUnit4::class) error is An annotation argument…
petestmart
  • 500
  • 11
  • 27
0
votes
1 answer

Could not transfer artifact com.squareup.okhttp3:mockwebserver:pom:4.9.1 from/to central (https://repo.maven.apache.org/maven2)

I have encountered a problem while importing the MockWebServer dependencies into my project com.squareup.okhttp3 okhttp 4.9.1
red
  • 3
  • 3
0
votes
0 answers

Cannot Mock the api responses in espresso using mockserverweb

I have been trying in vain and everytime I am just reaching a dead end. I am trying to look for a way to stub network responses with my json similar to cy.intercept in cypress using mockwebserver and espresso This is my code @Test fun…
Emjey
  • 2,038
  • 3
  • 18
  • 33
0
votes
1 answer

Android UI Tests fail due to mockwebserver

Actually in order to run my test on github action, i need to manipulate my test to following repo, Ui Test File: https://github.com/TheReprator/Wipro/tree/mockwebserver/appModules/factList/src/androidTest/kotlin/reprator/wipro/factlist/test Repo:…
Reprator
  • 2,859
  • 2
  • 32
  • 55
0
votes
0 answers

Mock Webclient beans created inside Configuration class - Spring Boot

I am creating multiple beans of WebClient inside configuration class because of different base urls. In my service class I am simply autowiring those beans and everything works fine. Now for writing JUnit of my service class I am using MockWebServer…
Harsh Kanakhara
  • 909
  • 4
  • 13
  • 38
0
votes
1 answer

Doesn't a test class using MockWebServer require a runner?

I have a very basic question, I'm new to unit testing and I have a test class in which I'm testing Spring WebClient using MockWebServer. All the tests run fine but why don't we need a runner when using MockWebServer? When using Mockito we annotate…
Shubham
  • 75
  • 1
  • 4
0
votes
1 answer

MockWebServer BasicAuth with Spring

I need to do tests by calling an external API, where I do the following: Service Class: public class BatchStatusClient { @Value("${batchStatusUpdate.username}") private String username; @Value("${batchStatusUpdate.password}") …
0
votes
0 answers

IntelliJ runs JUnit4 tests without a problem, maven test gets exception

I´m currently having nightmares testing my Spring WebClient code. Given the following simple method private String request(String uri, String body) { return webClient .method(HttpMethod.POST) .uri(uri) …