I have been using
JUnit for a few years now. Currently i am using 4.x version of JUnit. In most of the
test setups that i have worked on, JUnit is usually triggered from an
Ant script, something like this:
As can be seen, the test runs itself consists of 3 different steps - setup a server, run the tests and stop the server.
Personally, i would want to avoid that Ant script (or any other build script) because all it does is provide some hooks for "pre" junit start and "post" junit end lifecycles. I was wondering if there is a way i could intercept this lifecycle of JUnit from within
Java.
For example i would have a JUnitLifecycleListener:
Then the testcase would point the JUnit framework to this listener (or maybe some other way):
Note that this isn't the same as relying on the @BeforeClass or @Before constructs. Instead this has to be called once during the start and stop of JUnit framework itself (irrespective of whether Ant calls it or an
IDE).
Is this something possible in JUnit? Or are there other test frameworks similar to JUnit which provide this kind of hooks?