Skip to content

Mocking rest requests using Wiremock. A test is provided where the wiremock server is managed by using Testcontainers

Notifications You must be signed in to change notification settings

marcusblackhall/WiremockTestcontainers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Wiremock with Testcontainers

A project showing how to mock rest requests with use of Wiremock and Testcontainers.

Dependencies

Docker should be running locally on your machine. The project runs under Java 11 and the only dependencies are for testcontainers and testcontainers junit5.

Setup

FetchUser is a class that fetches user data using a java web client against a real url. The real url api is provided by https://reqres.in A wiremock mock response for the request is created in the folder src/main/resources/wiremock/mappings.

In test class FetchUserIT a wiremock container is started and its /home/wiremock folder is mapped to the project src/main/resources/wiremock folder.

Test run

When test FetchUserIT is run a wiremock container is created with testcontainers that exposes port 8080 and the volume /home/wiremock.

The Test then sets the url in the fetch user class to use the port and host mapped by testcontainers for the wiremock container.

The test checks that the response is the same as the one that is defined in the src/main/resources/wiremock folder.

To run the test use ...

mvn verify

Social media

There is a video available demonstrating this project on Youtube https://www.youtube.com/watch?v=iQ-2GbZ7pZE

About

Mocking rest requests using Wiremock. A test is provided where the wiremock server is managed by using Testcontainers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages