SBT has a nice hook which allows you to execute arbitrary code after all tests are run:
testOptions in Test += Tests.Cleanup( () => println("Cleanup"))
That works. My question is: I want to do some actual cleanup (stopping some services for example) but I can't import any dependencies which I've declared in the same build file. Is there any way to do this? I guess I need to put these on the sbt classpath or something, but I can't seem to find this in the docs.
P.S. I might be doing this in the wrong location, is there a better place to shutdown things after all tests are run?)
Complementing venechka's answer: I'm running integration tests using Specs2, and in specs there is no way of knowing when all tests have run. So I solved it pretty much the way venechka and you yourself already indicated, by loading a class from the project that does the cleanup when it's initialized:
testOptions in IntegrationTest += Tests.Cleanup( (loader: java.lang.ClassLoader) => {
loader.loadClass("com.mypackage.IntegrationTestCleanup").newInstance
} )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With