Posts

Showing posts with the label MockWebServer from OkHttp

Unit testing Java HttpClient with MockWebServer from OkHttp

Image
Hello everyone, here you will learn unit testing Java HttpClient with MockWebServer from OkHttp. The  Source code download link is provided at the end of this tutorial. The HTTP Client was added in Java 11 onwards. It can be used to request HTTP resources over the network. It fortifies HTTP/1.1 and HTTP/2, both synchronous and asynchronous programming models, handles request and replication bodies as reactive-streams, and follows the familiar builder pattern. MockWebServer makes it possible to facilely test how our apps comport when making HTTP/HTTPS calls. A mock web server is a program that mocks the behaviour of an actual remote server but doesn't make calls over the internet world. Technologies Used: Java 17 OkHttp MockWebServer Maven 3+ jackson databinder Final project directory: Okhttp mockwebserver and jackson databinder dependencies <properties> <maven.compiler.target> 17 </maven.compiler.target> <maven.compiler.source> 17 </ma