SBT assembly hook in test

SBT has a good hook that allows you to execute arbitrary code after running all the tests:

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

It works. My question is: I want to do some actual cleanup (for example, stopping some services), but I cannot import any dependencies that I declared in the same assembly file. Is there any way to do this? I think I need to put them in the sbt class path or something else, but I can not find it in the docs.

PS Maybe I'm doing it in the wrong place, is there a better place to stop working after all the tests?)

+6
source share
2 answers

Complementing venechka's answer: I run integration tests using Specs2, and there is no way in the specs to find out when all the tests were run. Therefore, I decided this to a large extent, like a wreath, and you yourself have already indicated by loading a class from a project that performs cleaning when it is initialized:

 testOptions in IntegrationTest += Tests.Cleanup( (loader: java.lang.ClassLoader) => { loader.loadClass("com.mypackage.IntegrationTestCleanup").newInstance } ) 
+7
source

You cannot use the classes that are added with the dependency library in the project (you can add libraryDependencies to the project / project, but I would not recommend adding in 2 places). Instead, you can call the cleanup method, which is located in your project sources, and which has access to the declared library dependencies.

+4
source

Source: https://habr.com/ru/post/911776/


All Articles