Devhook equivalent for "sbt test"?



Wonder if a similar mechanic is possible for test mode, as is described for dev mode in this page.

The point would be to clean up databases after unit tests are over. Right now I’m doing it manually with a script.

(Rich Dougherty) #2

You’re in luck because it’s easier for sbt test than for sbt run. :slight_smile: For run we needed to write our own custom hooks in Play because the run task is a special Play task. For normal sbt tasks like test you can use sbt’s built in functionality. Take a look at which runs you through adding code to run before/after other tasks, along with diagrams of how things work, etc.


Adding for future visitors:

I ended up using something like this:

testOptions in Test += Tests.Setup( () => println("Setup") )
testOptions in Test += Tests.Cleanup( () => println("Cleanup") )

As found here: