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.
Good solution, but no example with testcontainers and r2dbc.
This guys just avoids it
Which hindside I understand, and this one is with mockmvc:
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:
Have fun!
Photo by Emil Priver on Unsplash