Testcontainers, Postgres, Kotlin

Опубликовано: 29 Ноябрь 2024
на канале: Pairing with Duncan
623
49

If you check our Kotlin Gilded Rose codebase out of GitHub (https://github.com/dmcg/gilded-rose-tdd) and try to build it, you will find that you need to be running Postgres just in order to compile things, and then again in order to run the unit tests.

That’s not too much of an issue on my Mac, but with the expansion of the team we would like to set up a cloud continuous integration server, and there we are going to want to manage the Postgres lifecycle inside our build.

It would be a start if only there was a way to manage Docker containers in our tests. Containers in our tests ... Testcontainers!

In this episode

00:00:35 Review our database lifecycle
00:03:01 Never upgrade a thing just before recording
00:05:12 DBItemsTests currently uses a running Postgres
00:06:25 DBItemsTests has to clear the decks before running its tests
00:07:16 Testcontainers allow a fresh database per test
00:08:00 AI Assistant now lets us just type and tab
00:08:57 Let's start a container for each test
00:11:27 If we have a clean database, we're going to have to create the schema
00:12:37 Run our migrations in the test with Flyway
00:14:08 AI for error messages
00:15:20 Debugging Flyway
00:18:16 It turns out we need to add a dependency
00:19:20 Now we have to match the database user to the migration user
00:20:22 One last irritating intermittent issue
00:23:26 Pragmatism FTW
00:25:24 Now, is Testcontainers fast enough?

There is a playlist of TDD Gilded Rose episodes -    • Test Driven Gilded Rose in Kotlin  

The codebase is available on GitHub https://github.com/dmcg/gilded-rose-tdd

If you are going to be at KotlinConf 2025, or even just in Copenhagen in May, then you should totally be signing up for the workshop that Nat Pryce and I are running. It’s called Refactoring to Functional Kotlin, and will give you hands-on experience of taking legacy code and safely migrating it to a functional style. Places are limited, so buy now at https://kotlinconf.com/workhops

If you like this video, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (http://java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style.


Смотрите видео Testcontainers, Postgres, Kotlin онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pairing with Duncan 29 Ноябрь 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 623 раз и оно понравилось 49 людям.