feat: run @StormTest and @DataStormTest against a real database with Testcontainers - #509
Merged
Merged
Conversation
…Testcontainers A database attribute on both annotations starts a Testcontainers-managed container of the named database once per JVM and shares it across the test classes of the run; each class, or Spring context, receives a freshly created database inside the container, so scripts run against an empty database as they do on H2 and classes never observe each other's tables. The image is settable and defaults to a pinned version. Testcontainers stays out of storm-test's dependencies: a test naming a container database needs the database's Testcontainers module and JDBC driver on the classpath and fails with a message naming both when one is missing. Fixes #502
…mark the new storm-test types The testing guide splits the database section into dependencies, image choice, container sharing and direct use; the dialects, Ktor and installation pages point at the attribute instead of at docker-compose or a custom DataSource; the Spring slice section lists what it sets and why. TestDatabase keeps its container details in one nullable record and DatabaseContainer's endpoint is nullable until started, as the null-marked package requires.
This was referenced Aug 16, 2026
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #502
What
@StormTestand@DataStormTestgaindatabaseandimageattributes that run the test on the database the application deploys on, in a Testcontainers-managed container, without any container wiring in the test class:st.orm.test.TestDatabase:H2(default),POSTGRESQL,MYSQL,MARIADB,MSSQL_SERVER,ORACLE, each with a pinned default image (postgres:17,mysql:8.4,mariadb:11.8,mcr.microsoft.com/mssql/server:2022-latest,gvenzl/oracle-free:23-slim-faststart). Majors are pinned, patch levels float.imagenames another tag or another distribution of the database (pgvector/pgvector:pg17).DatabaseContainer: JVM-wide registry keyed by database and image; the container starts on first use and is shared by every test class of the run.createDatabase()provisions a fresh database inside the container per test class (JUnit) or per Spring context (slice): a new catalog on PostgreSQL, MySQL, MariaDB and SQL Server, a new user on Oracle, dropped when the class or context completes. That is what makes reuse safe beyond per-test rollback: scripts run into an empty database with no drop guards, and classes never observe each other's tables. Exposed publicly (TestDatabase.POSTGRESQL.container()) for setups outside the annotations.provideddependency ofstorm-test. OnlyJdbcContainersreferences Testcontainers types and it is loaded after aClass.forNamecheck, so a missing module or driver fails withadd org.testcontainers:postgresql in test scoperather than aNoClassDefFoundError; tests on H2 pull in nothing new.databasecombined withurl, adataSource()factory, orimagewithout a container database fails with anExtensionConfigurationExceptionnaming the conflict.@DataStormTest: a secondContextCustomizerFactoryprovisions the database, pointsspring.datasource.url/username/passwordat it, setsspring.test.database.replace=noneand, unless the application configures it,spring.sql.init.mode=alwayssoschema.sqlinitializes the container database as it does the embedded one. The customizer is part of the context cache key.storm-spring-boot-test-autoconfigurenow depends onstorm-test, so both annotations share one container within a JVM.docs/testing.md(new section, attribute table),docs/spring-integration.md,docs/ai.md; CHANGELOG entry.Notes
org.testcontainers.containersacross its jars, so it can never berequires staticfrom a module descriptor.storm-testcompiles it from the classpath with--add-reads storm.test=ALL-UNNAMED(compiler and javadoc), commented inmodule-info.java.ltstag (9.7): Testcontainers 1.21.3's bundledmy.cnfsetsinnodb_log_file_size, which MySQL 9.x rejects, so 9.7 andlatestfail to start under the Boot 3.5 BOM's Testcontainers.container-license-acceptance.txtmechanism applies and is documented.storm-test's tests now need Docker: real container tests for all five databases (lifecycle, reuse across classes, fresh database per class, image override, configuration conflicts, missing-dependency message via an isolated class loader), plus a PostgreSQL slice test. Locally the whole storm-test suite runs in about 50s with images cached.databaseparameter for Ktor'stestStormApplication.