I am writing in the context of the SQL script execution in integration tests.

Spring documentation says about default script detection.

Default Script Detection

If no SQL scripts or statements are specified, an attempt is made to detect a default script, depending on where @Sql is declared. If a default cannot be detected, an IllegalStateException is thrown.

  • Class-level declaration: If the annotated test class is com.example.MyTest, the corresponding default script is classpath:com/example/MyTest.sql.

  • Method-level declaration: If the annotated test method is named testMethod() and is defined in the class com.example.MyTest, the corresponding default script is classpath:com/example/MyTest.testMethod.sql.

This is an awesome feature. Since I am working with both create and destroy script (before- and after-test), it would be interesting to introduce a convention for post-method scripts

Today I have a project where I introduce @Sql for both scripts (note that I didn't know about the existing convention, so I used an underscore on my own)

@Sql(value="/com/acme/MyClass_myMethod_init.sql")
@Sql(value="/com/acme/MyClass_myMethod_destroy.sql", executionPhase = AFTER_TEST_METHOD)
@Test
public void myMethod()

It could be interesting that scripts named MyClass.myMethod.after.sql run after test, as well as scripts named MyClass.myMethod.before.sql (and MyClass.myMethod.sql to preserve backward compatibility) are run before.

I haven't tried anything else yet.

Comment From: sbrannen

This is an awesome feature.

Glad to hear you like it!

This issue is effectively a duplicate of #17907 (which got bulk closed), so I'll close this issue and re-open the other one.

Comment From: djechelon

From September, or the half of it, I will be personally available for coding on this feature.

May I ask what is (are) the component(s) involved in executing the annotation? So I will start studying the possible implementation

Comment From: sbrannen

@djechelon, please note that this issue was closed in favor of #17907.

May I ask what is (are) the component(s) involved in executing the annotation? So I will start studying the possible implementation

This support is handled by the org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener.