Devhook equivalent for "sbt test"?

sbt

#1

https://www.playframework.com/documentation/2.6.x/SBTCookbook

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 https://www.scala-sbt.org/1.0/docs/Custom-Settings.html#Execution+semantics+of+tasks which runs you through adding code to run before/after other tasks, along with diagrams of how things work, etc.


#3

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: https://github.com/sbt/sbt/issues/2056