Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT cleanup hook in test

Tags:

scala

sbt

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?)

like image 494
Albert Avatar asked Mar 27 '12 16:03

Albert


1 Answers

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
} )
like image 141
Arjan Blokzijl Avatar answered Sep 22 '22 07:09

Arjan Blokzijl