I have many junit 4 test classes with many tests.
Many of these tests need a DataSource to access a database.
To speed up tests, I would like to share a single DataSource for all test classes.
That would avoid connection cost.
So I have put the DataSource in a static variable.
But I have not found a way to close it!
With @Rule + TestWatcher, we can execute code before and after a single test…
With @ClassRule + TestWatcher, we can execute code before and after a single test class…
But how to execute code after the execution of all executed test classes ?
The test suite doesn’t seems appropriate, because I am executing either all, one, or any subset of the junits tests.
Any idea?
Installing JVM shutdown hook does not appear too ugly in that case.
Far more reliable than a finalize() method called only if the object is garbage collected.
Not called if process interrupted, but in that case there nothing can be done anyway. So I did not find major drawbacks.
Thanks.