I am writing a specs2 Unittest for my scala software. The execution is working well. The only problem I have, is that I need to clean up after all test are finished. I just cannot find any solution for that. Is there a way to execute some functions after all test are finished?
Asked
Active
Viewed 2,677 times
2 Answers
10
You need to add a Step at the end of your specification:
import org.specs2.mutable._
class MySpec extends Specification {
// lots of examples here
// cleanup there
step(cleanUp())
}
Eric
- 15,249
- 36
- 60
-
1Is it possible that if any step throws an exception then not running cleanUp? – Robertiano Nov 27 '12 at 08:59
-
Yes but that will fail the run. – Eric Nov 27 '12 at 17:33
-
This will fail the run, but will not kill your server that was started in the beginning of the test – Vitamon Aug 23 '17 at 21:39
0
You can try to use After with After
and implement def after
function.
Example:
class Context extends Specification {
....
}
trait trees extends mutable.After {
def after = cleanupDB
}
Robertiano
- 352
- 1
- 6
-
Does this work for the specification? As in: class Spec extends Specification with After { ... } – tgr Nov 26 '12 at 17:59
-
1*After* runs after each test, but the OQ referred to cleanup after *all* tests. – Rick-777 Sep 30 '13 at 15:49