I'd like test classes to be aware if they are currently executed inside a Suite
or not.
I have a test suite which starts a server before all tests and shuts down the server after all tests, using ExternalResource
. Works perfect.
While writing new tests, I'd want to run a single test (or all from the same test class) to also start and stop the server. So I wanted those classes to become aware if they are currently executed inside a suite or not, and initiate server start accordingly.
That seems to be impossible. The suite Description
is never passed to @Rule
s or @ClassRule
s it seems. Neither can I get a reference to the current Runner
that runs the current test.
Is there a way to do that?
Update due to the first proposed answer:
Please note that there are many other tests that may run before the test suite and after it. Therefore I can't rely on a JVM shut down. My main demand is that I'd like to run a single test from within my IDE (eclipse) right after writing the test, and still have the server start up and shut down. That should not happen for every test within the suite though.