-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce class-level execution phases for @Sql
#27285
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. I've added a couple comments for your consideration.
spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java
Show resolved
Hide resolved
spring-test/src/main/java/org/springframework/test/context/TestContext.java
Show resolved
Hide resolved
@Sql
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the PR looks pretty good.
Please revert changes that deleted intentional blank lines, and please rebase on main
.
Thanks!
FYI: we would like to include this feature in the upcoming Spring Framework 6.1 RC1. So if you don't have time to rebase on |
735b29c
to
15f8179
Compare
That's awesome. Thanks a lot. I have updated the PR. Due to its age, it required some rework. I also improved a test. If I should do anything else, like adding the exception as @snicoll suggested, let me know. |
Thanks!
I can well imagine.
OK, I'll check it out in the coming week.
Yes, please throw an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR is almost ready, though I've requested a few additional minor changes.
...est/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java
Outdated
Show resolved
Hide resolved
...est/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java
Outdated
Show resolved
Hide resolved
...-test/src/test/java/org/springframework/test/context/jdbc/AfterTestClassSqlScriptsTests.java
Outdated
Show resolved
Hide resolved
@sbrannen I applied the requested changes. |
This commit introduces BEFORE_TEST_CLASS and AFTER_TEST_CLASS execution phases for @Sql. See gh-27285
This PR is a proposal to address #18929.
So far, scripts or inline statements declared with
@Sql
run before or after every test method. It is not possible to declare a script or inline statement to be run once before any test method has been run or after all test methods have been run.This PR makes it possible by adding two additional execution phases,
BEFORE_TEST_CLASS
andAFTER_TEST_CLASS
. Scripts or inline statements withBEFORE_TEST_CLASS
will be run once before any test method has been started. Anything marked withAFTER_TEST_CLASS
will be run after all test methods have been completed.#1835 added
MergeMode
.MergeMode
allows method-level@Sql
annotations to override or extend class-level@Sql
annotations. In my proposal,MergeMode
has no effect on@Sql
annotations with an execution phase ofBEFORE_TEST_CLASS
orAFTER_TEST_CLASS
. The reason is that any method-level processing would come too late to influence a script or inline statement that runs when the test context is being set up. Furthermore, it would pose the question how to resolve conflicting annotations. If one test method wished to override a class-levelBEFORE_TEST_CLASS
annotation while others would not, honoring that wish would effectively turnBEFORE_TEST_CLASS
intoBEFORE_TEST_METHOD
.AFTER_TEST_CLASS
has roughly the same problem, just backwards.