Issue calling Setup/Cleanup in tests
See original GitHub issueNormally you can do some setup and tear down before and after your tests:
testOptions in Test += Tests.Setup( loader => ... )
testOptions in Test += Tests.Cleanup( loader => ... )
Note: When forking, the ClassLoader containing the test classes cannot be provided because it is in another JVM. Only use the () => Unit variants in this case.
So when your tests are forked like Play’s you have to do this:
testOptions in Test += Tests.Setup( () => println("Setup") )
testOptions in Test += Tests.Cleanup( () => println("Cleanup") )
I want to start a DB process before my tests run and stop the process after. The issue I’m having is that I don’t know how to share a variable between setup and cleanup so that I can take the DB that I started in setup and call the stop method on it in cleanup.
A suggestion would be to have Tests.Setup and Tests.Cleanup replaced by a Tests.Hook which takes a class providing Setup and Cleanup methods. This class could then have member variables shared between the two functions
Issue Analytics
- State:
- Created 8 years ago
- Comments:19 (17 by maintainers)
For anyone looking for global setup,
test
task across all subprojects, global cleanup, here’s a way of solving this.Im trying something based on @eed3si9n sketch above, but in my case the middle of the sandwich is
run
nottest
.It seems that if run throws an exception and exits non-zero, the cleanup step gets skipped?