Mocking Spring’s reactive WebClient in Kotlin, using MockK for UnitTests

This is purely a quick Note To Self, so that I can find it again, when googling for it 🤓

Let’s assume we want to test a method, invoking a WebClient call in a Unit Test (no Integration Test). Example:

private fun loadSomething(id: String): SomeThing {
return runBlocking(Dispatchers.IO) {
webClient
.get()
.uri("/someurl/{id}", id)
.exchangeToMono { response ->
if (response.statusCode() == HttpStatus.OK) {…

--

--

--

Leader, self-taught developer with interests in AI/FBP/Gaming/Automation/Trading.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Android Image Lighting Control and Color Filtering

To Store The Secret String Data in .So File Under The Android Project by Adding Gradle Plugin

How to Organize Android Package / Folder Structure?

AZ Screen Recorder Mod Apk Without Watermark 2021

AZ Screen Recorder Mod Apk Without Watermark 2021

Build Your First Android App

Unleash the potential of your unrooted Android phone

Keyboard Pushes the Content up / Resizes the Screen Problem in Flutter

Stripe Payment Integration with android

Stripe Payment Integration with android

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Daniel Bunte

Daniel Bunte

Leader, self-taught developer with interests in AI/FBP/Gaming/Automation/Trading.

More from Medium

Compile-Time Dependency Injection with Dagger 2

Deep dive into Pattern Matching for Java

Connecting multiple buckets in a Spring Application

Build Simple REST API Using Vert.x in Kotlin