Skip to content

Run @StormTest against a real database with Testcontainers #502

Description

@zantvoort

@StormTest runs on H2. The url() attribute takes a raw JDBC string, so pointing a test class at PostgreSQL means standing up the container, wiring the lifecycle and building the URL by hand, per project.

That leaves the first test a new user writes running on the one dialect Storm supports that hides the most. 1.14 was largely about SQL that is correct on every dialect rather than on the permissive ones, and the differences it dealt with are exactly the ones H2 papers over: upsert paths, sequence discovery, identity grouping, keyword escaping. A green H2 suite is not evidence the application works.

Proposal

A database attribute that resolves a container instead of a URL:

@StormTest(database = POSTGRES, scripts = {"/schema.sql", "/data.sql"})
class VisitRepositoryTest {

    @Test
    void findsVisitsByPet(ORMTemplate orm) {
        // running against a real PostgreSQL
    }
}
  • Testcontainers stays optional. storm-test declares it provided; the attribute fails with a message naming the missing dependency rather than a NoClassDefFoundError, and H2 users pull nothing new.
  • Containers are reused across test classes in a run, keyed by database and version, so the cost is paid once rather than per class.
  • The image tag is settable on the annotation and defaults to a pinned version, not latest.
  • Per-test rollback (Per-test rollback for @StormTest #387) applies unchanged, which is what makes container reuse safe: classes share a container and still never observe each other's writes.
  • url() keeps working for anyone pointing at their own database.

Also on the slice

@DataStormTest (#200, #401) should take the same attribute, for the same reason. A Spring slice that can only run on H2 has the same blind spot.

Notes

  • The reactor already runs five dialects on Testcontainers in storm-postgresql, storm-mysql, storm-mariadb, storm-mssqlserver and storm-oracle. This makes that wiring a supported annotation attribute instead of per-project boilerplate.
  • Script execution, parameter injection and SqlCapture are dialect-independent and should need no changes.

Tasks

  • database attribute on @StormTest, resolved through Testcontainers, with a pinned default image tag
  • Testcontainers as a provided dependency, with a clear failure when the attribute is used without it
  • Container reuse across test classes within a run, keyed by database and version
  • Same attribute on @DataStormTest
  • Docs: testing against the database you deploy on

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions