spring-projects / spring-projects/spring-framework

Add mechanism to disable inherited `@Sql` class-level execution phase scripts/statements in `@Nested` test class

Open
#31,378 2 comments 0 reactions 1 assignee View on GitHub

@sbrannen is already working on this.

Since Oct 8, 2023.

in: test type: enhancement
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

This is a follow-up to #27285 to ensure that users can "disable" class-level execution phase scripts and statements that would otherwise be inherited in a @Nested test class.

Commits b98b9999973637f72ee7734a9369db97ee3344a3 and d1b43386b1bc23f87a3cfd0e5de5a3d6ca23f4cb introduced tests for the status quo for @Sql scripts/statements inherited from the enclosing class of a @Nested test class.

Those tests pass; however, if you change "recreate-schema.sql" to "schema.sql" in the class-level @Sql declarations on those enclosing test classes, the @Nested test classes will then fail since the class-level execution phase scripts/statements are executed for the enclosing class and then again for each @Nested class, which is probably not what the user intends.

Method-level @Sql declarations can already be configured to override or merge with class-level @Sql declarations via @SqlMergeMode. So we might be able to "disable" class-level execution phase scripts and statements by introducing additional enum constants in SqlMergeMode.MergeMode, or we may need to introduce some form of boolean inheritClassLevelExecutionPhases flag.

In summary, I think we need a way for a @Nested test class (or a subclass of a test class) to disable inheritance of class-level execution phase scripts/statements, but the nature of how this will be "disabled" is yet to be determined.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.