spring - Using annotation @Sql, is it possible to execute scripts in Class level before Method level? -
i want execute 2 scripts before every test method, want define scripts execute before specific methods. using spring framework , @sql annotations, possible?
@runwith(springjunit4classrunner.class) @contextconfiguration("/web-inf/application-context.xml") @dirtiescontext(classmode = classmode.before_each_test_method) @sql({ "/database/drop_schema.sql", "/database/create_schema.sql" }) public class centralservicetestcase { // want run "drop_schema.sql", "create_schema.sql" // , "basic_data.sql" here @test @sql({ "/database/basic_data.sql" }) public void processactionwithsuccess() { } // want run "drop_schema.sql" , "create_schema.sql" here @test public void anothertestmethod() { } } running code "basic_data.sql" executed. how solve problem? have remove @sql anotation class , replicate each method "/database/drop_schema.sql" , "/database/create_schema.sql" defined?
update: may potentially addressed in spr-14357.
the 2nd paragraph of javadoc @sql explicitly states:
method-level declarations override class-level declarations.
this documented in executing sql scripts declaratively @sql section of reference manual.
thus, no, unfortunately not possible have scripts declared via @sql @ class level executed if @sql defined @ method level.
if spring support such combinations, please create jira issue requesting feature , select test component.
thanks!
sam (author of spring testcontext framework)
Comments
Post a Comment