When I invoke
mvm test, I want to execute a
setup.sql script before Surefire JUnit is invoked and then execute a
teardown.sql script after.
I know from <a href="https://stackoverflow.com/questions/4821686/how-can-i-add-a-maven-exec-task-to-execute-on-mvn-test" rel="nofollow">questions like this</a> how to execute scripts during the test phase, but I have no idea how to define this specific sequence of events. Thank you!Answer1:
Not with the surefire plugin but with its sibling the failsafe plugin. They both execute Tests but in different life-cycle phases. The surefire plugin in test and the failsafe plugin in integration-test. See <a href="https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference" rel="nofollow">life-cycle phases</a> and the <a href="https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings" rel="nofollow">default plugin bindings</a>.
The advantage of the failsafe plugin running in the integration test phase is that there are pre- and post- phases.
Since you mention some sql script it seems you want to prepare a database. At that point you are not really doing unit testing anymore but writing an integration test. So using the failsafe plugin makes the most sense here.