Questions tagged [wiremock]

Library used for stubbing and mocking web services.

Wiremock is a library written in Java by Tom Akehurst. It is used for stubbing and mocking web services. It supports HTTP response stubbing, request verification, proxy/intercept, record/playback of stubs and fault injection, and can be used from within a unit test or deployed into a test environment.

For more information see http://wiremock.org

894 questions
96
votes
5 answers

How to replace WireMock @Rule annotation in JUnit 5?

I'm using WireMock in my tests and have such a line of code: @Rule public WireMockRule wireMockRule = new WireMockRule(8080); I want to switch to JUnit 5. So I added the next dependency (using…
IKo
  • 4,998
  • 8
  • 34
  • 54
44
votes
2 answers

Wiremock: Multiple responses for the same URL and content?

Also shared here: https://github.com/tomakehurst/wiremock/issues/625 I'm writing an integration test to verify that my application that interacts with a REST API handles unsuccessful requests appropriately. To do this, I'm wanting to simulate a…
rugden
  • 1,085
  • 2
  • 9
  • 11
29
votes
2 answers

Using WireMock how can we verify that a request of a given url has NOT been made?

Given the following unit test, I can easily test if a request of a particular url has been made. Is there a way to do the opposite, verify that a request of a particular url has NOT been made? i.e. verify that a request was made:…
TyrionWebDev
  • 291
  • 1
  • 3
  • 3
28
votes
7 answers

How to Integration Test spring-cloud-netflix & Feign, using WireMock

I use Spring-Cloud-Netflix for communication between micro services. Let's say I have two services, Foo and Bar, and Foo consumes one of Bar's REST endpoints. I use an interface annotated with @FeignClient: @FeignClient public interface BarClient { …
Bastian Voigt
  • 5,311
  • 6
  • 47
  • 65
25
votes
2 answers

Wiremock - "URL does not match" even though it is same

I am facing an issue that Wiremock says my URLs don't match even though they are the same. Obviously I am missing something. What am I doing wrong? WireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo("/test/url?bookingCode=XYZ123&lastName=TEST")) …
Abbin Varghese
  • 2,422
  • 5
  • 28
  • 42
25
votes
5 answers

Is it possible to simulate connection timeout using wiremock tools?

I know that it can simulate SocketTimeoutException by using withFixedDelay, but what about ConnectionTimeoutException?
Developer87
  • 2,448
  • 4
  • 23
  • 43
24
votes
3 answers

How to enable verbose logging in non standalone wiremock

I see that there are instructions on enabling verbose logging for wiremock when running it in standalone fashion at http://wiremock.org/running-standalone.html (see --verbose). How do I enable the same when starting it from a java code?
Superaghu
  • 775
  • 1
  • 5
  • 15
22
votes
4 answers

Connection refused when using wiremock

I have this piece of code in a Junit, where I clearly set the port to 8888 when(clientUtils.getLinkUrl(eq(HOSTELS_MICROSERVICE.name()), eq(HOSTELS_MICROSERVICE.name()), anyMap())) …
Sandro Rey
  • 2,429
  • 13
  • 36
  • 80
22
votes
1 answer

Why would I use MockWebServer instead of WireMock?

Every time when I need to mock some http requests my first choise is WireMock (which is actually standard for that I think), but today I discovered some alternative tool - MockWebServer. What are pros and cons of WireMock vs MockWebServer?
Paweł Szymczyk
  • 1,638
  • 15
  • 20
22
votes
1 answer

wiremock equivalent for websockets?

I have used wiremock for testing http calls, but my current work requires websockets and I was wondering if anyone has found/used a library for standing up a localhost that will create a websocket connection that you can mock responses. I have…
Randy
  • 1,400
  • 2
  • 12
  • 30
21
votes
9 answers

Set property with wiremock random port in spring boot test

I have a Spring Boot test that uses wiremock to mock an external service. In order to avoid conflicts with parallel builds I don't want to set a fixed port number for wiremock and would like to rely on its dynamic port configuration. The application…
21
votes
4 answers

Can't turn off debug logging for Wiremock

I'm using Wiremock for my tests in a Spring Boot app. I can't seem to get the logging to not output all debug logs, which makes my test runs very verbose. I see it use SLF4J on startup: DEBUG wiremock.org.eclipse.jetty.util.log - Logging to…
James McMahon
  • 48,506
  • 64
  • 207
  • 283
19
votes
3 answers

wiremock issue when upgrading to Spring Boot 3

When upgrading my Spring Boot 2.5 to 3.0 , I am facing some issues with Wiremock, probably due to the move to jakarta namespace. Even upgrading to latest wiremock-jre8 , ie 2.35.0 (as of december 2022) doesn't seem to help. I get this error…
Vincent F
  • 6,523
  • 7
  • 37
  • 79
19
votes
4 answers

Stubbing with Wiremock - WithBodyFile Location other than _files

Wiremock Documentation states that the location of the file specified in withBodyFile should be in src/test/resources/__files. I would like to have file in src/test/resources/Testing_ABC/Testcase2/myfile.xml. Is there any way I can achieve this ? I…
Ragini
  • 1,509
  • 7
  • 28
  • 42
17
votes
5 answers

How can I make WireMock port more dynamic to use it for testing service

I am using wiremock to mock github api to do some testing of my service. The service calls github api. For the tests I am setting endpoint property to github.api.endpoint=http://localhost:8087 This host and port are the same as wiremock server…
niemar
  • 612
  • 1
  • 7
  • 16
1
2 3
59 60