-
object TestDatabase { private val mySQLContainer: MySQLContainer = MySQLContainer("mysql:8.0.26").apply { withDatabaseName("test-db") withUsername("test-user") withPassword("test-password") start() // Start the container } init { val config = HikariConfig().apply { jdbcUrl = mySQLContainer.jdbcUrl username = mySQLContainer.username password = mySQLContainer.password driverClassName = "com.mysql.cj.jdbc.Driver" maximumPoolSize = 10 } val dataSource = HikariDataSource(config) // This doesn't connect to the database but provides a descriptor for future use // In the main app, we would do this on system start up // https://github.com/JetBrains/Exposed/wiki/Database-and-DataSource Database.connect(dataSource) // Create the schema transaction { SchemaUtils.create(Users) } } }
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
-
Testcontainers
Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
In this article, we will explore how to use Testcontainers and Exposed, a lightweight ORM framework for Kotlin, to create a controlled environment for testing MySQL Database operations.
-
You can find the complete source code for this tutorial on GitHub