How to execute scripts before and after SureFire test phase


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!


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.


  • How to detect when user used Password AutoFill on a UITextField
  • NoSuchFieldError: RESOURCE_PREFIX with a maven project using tess4j
  • Presenting NSOpenPanel as sheet synchronously
  • Maven + Surefire/Failsafe - forkMode=“perthread” is not working … a workaround?
  • @RunWith causes Maven to ignore my Test running with my own runner
  • Get last insert id of Postgresql
  • Is it possible to generate a unique numeric value for each row in an iSeries table without looping?
  • maven-dependency-plugin ignores outputDirectory configuration
  • C++ - Is destructor called when a vector holds objects?
  • Submission of new app with iAds
  • reduce/reduce conflicts using ocamlyacc
  • How to detect left mouse click but not when the click occur on a UI Button component [closed]
  • Any nice way to generate a timeline view of commits from subversion?
  • python: forcing relative imports to search from script file
  • Python 3.2.2, error(scripts to exe)
  • Jenkins Grails plugin does not list lastest versions of Grails
  • Iron Router: How do I send data to the layout?
  • Can someone please explain to me in the most layman terms how to use EventArgs?
  • How to generate and display a QR Code in ionic 2
  • Sequential (transactional) API calls in angular 4 with state management
  • how to display data from 1st point on words on y axis for line chart in d3.js
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Test if a set exists before trying to drop it
  • Row Count Is Returning the incorrect number using RaptureXML
  • When to use `image` and when to use `Matrix` in Emgu CV?
  • What is the “return” in scheme?
  • Read text file and split every line in MSBuild
  • C# - Serializing and deserializing static member
  • Excel - Autoshape get it's name from cell (value)
  • Java applet as stand-alone Windows application?
  • Javascript Callbacks with Object constructor
  • WinForms: two way TextBox problem
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Matrix multiplication with MKL
  • Error creating VM instance in Google Compute Engine
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • Why joiner is not used after Sequence generator or Update statergy
  • Append folder name and increment by 1 using batch script
  • Converting MP3 duration time