Skip to content

Add dbUnit annotations for running SQL scripts around tests #937

Description

@jeffjensen

Split out of #753, which delivers the declarative setup, teardown, verification, and
configuration annotations. SQL script execution was deliberately left out of that scope
so it can be designed on its own.

Ask

Add annotations that run plain SQL script files around the dbUnit test lifecycle, at
class or method level, with method-level overriding class-level like the rest of the
annotation family:

  • a "before" hook that runs one or more .sql files ahead of dataset loading — the
    usual use is schema DDL or a stored-procedure definition the dataset depends on
  • an "after" hook that runs one or more .sql files following teardown

Prior art in the community forks calls these @DbUnitInit, @SqlBefore, and
@SqlAfter; naming should follow whatever the #753 family settles on.

Why it is not trivial

dbUnit has no SQL script execution capability at all today — there is no equivalent of
Spring's ScriptUtils or a SqlScriptExecutor anywhere in the codebase. This needs a
real implementation, not a wrapper, and the design has to decide:

  • statement splitting — a naive split on ; breaks on semicolons inside string
    literals, comments, and BEGIN ... END blocks, which matters for the
    stored-procedure case that motivates the feature
  • whether a failing statement aborts the script or is tolerated, and whether the script
    runs in its own transaction
  • which connection the script runs on, and whether it participates in the
    connection-reuse behaviour the rest of the lifecycle uses
  • encoding and resource resolution, which should match the dataset path convention the
    Add dbUnit annotations for declarative test setup, verification, and configuration #753 annotations establish

Notes

Depends on #753 landing first, since it extends that annotation family and should share
its package, path-resolution convention, and precedence rules.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: annotationsdbUnit annotations for test configuration

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions