Integration Tests in Spring Boot, Webflux, Kotlin, R2DBC, PostgreSQL, Testcontainers

Integration Tests in Spring Boot, Webflux, Kotlin, R2DBC, PostgreSQL, Testcontainers

As a developer, it's important to constantly work on improving your skills, and for me, that meant delving into the world of Kotlin and Reactive programming. To challenge myself, I decided to work on a personal project that utilized Spring Boot, WebFlux, and R2DBC to build a backend with a PostgreSQL database.

However, I ran into some difficulties when it came to writing integration tests using Testcontainers. While many online tutorials suggested using WebFluxTest, I didn't want to disable any autoconfiguration or deviate from my familiarity with Spring Boot. So, I set out to write integration tests that fully utilized my project's configuration.

I faced a lot of issues when using SpringBootTest, such as unrecognized routes and failed connections to R2DB, problems with configuration webtestclient.

I noticed that a lot of people on the internet have the same issue, but nobody brings a proper solution.

GitHub - sdeleuze/webflux-kotlin-web-tests: This projects shows how to use @WebTestClient with Kotlin and a WebFlux server (annotation or functional)
This projects shows how to use @WebTestClient with Kotlin and a WebFlux server (annotation or functional) - GitHub - sdeleuze/webflux-kotlin-web-tests: This projects shows how to use @WebTestClient...

Good solution, but no example with testcontainers and r2dbc.

This guys just avoids it

Why I avoid writing integration tests in WebFlux and Kotlin - Adrian Marszalek
I love Kotlin and I like writing enterprise applications using Spring. Kotlin and Spring is a great combo to work with. But there’s definitely room for improvements when it comes to Spring WebFlux test support and Kotlin type inheritance.

Which hindside I understand, and this one is with mockmvc:

Kotlin Spring Boot Unit Testing & Integration Testing with JUnit5 and Mockk ✔🚀
Let’s make a Simple CRUD application with MongoDB and Kotlin SpringBoot and do Integration and Unit testing with Junit5 and Mockk.

After much trial and error, and a fair bit of Googling, I was finally able to solve these issues and successfully write my integration tests.

So if anyone would like to know how I did it:

GitHub - arnovr/demo-kotlin-webflux-spring-integration-test
Contribute to arnovr/demo-kotlin-webflux-spring-integration-test development by creating an account on GitHub.

Have fun!

Photo by Emil Priver on Unsplash