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
Improve documentation for @Sql
execution phases regarding lifecycle
#32343
Comments
Hi @marwin1991, Congratulations on submitting your first issue for the Spring Framework! 👍 The behavior you have described is not a bug but rather the expected behavior. Spring cannot execute SQL scripts without access to the When you use the Since In other words, the invocation order of those methods is required to change when using the Have you considered converting your static {
System.out.println("Calling init method");
var = 1;
// init here mock server f.e
// mockWebServer = new MockWebServer();
// mockWebServer.start();
} |
@Sql
annotation in tests, @DynamicPropertySource
is executed before method @BeforeAll
@Sql
with BEFORE_TEST_CLASS
, @DynamicPropertySource
is executed before @BeforeAll
method
The Javadoc for
However, that is a bit misleading since one can infer that the SQL scripts and statements may be executed after "before class level" callbacks, which is not the case. In light of that, I am repurposing this issue to improve the documentation. |
@Sql
with BEFORE_TEST_CLASS
, @DynamicPropertySource
is executed before @BeforeAll
method@Sql
's BEFORE_TEST_CLASS
mode regarding lifecycle
Thank you for your clarification ❤️ I was thinking the order of sql BEFORE_TEST_CLASS is as follows:
|
@Sql
's BEFORE_TEST_CLASS
mode regarding lifecycle@Sql
execution phases regarding lifecycle
@marwin1991, you can see the updated documentation here: |
@sbrannen 👍🏼 |
Affects:
spring-test
6.1.4There is a bug, when using
@Sql
withBEFORE_TEST_CLASS
.Without this annotation the order of execution of methods is:
@BeforeAll
@DynamicPropertySource
(often used to start some mock, then pass it to properties)
BUT when
@Sql
withBEFORE_TEST_CLASS
is used, the order is:@DynamicPropertySource
@BeforeAll
I have created sample repo: https://github.com/marwin1991/sql-before-class-bug-reproduction
with tests:
Second test not passing, because the order IMO is incorrect: it should not change after adding
@Sql
.The text was updated successfully, but these errors were encountered: