Test before/after hooks run in the test JVM

Hi,

First post so be gentle please!

I have a Java project with some JUnit tests.
I’d like some code to run on every test so I use code like this:

beforeTest { descriptor ->
logger.lifecycle("OIS B - bpmServerIntegrationTest - running test: " + descriptor)
}

Am I right in saying that this closure logic runs in the main gradle JVM rather than the JVM which is executing the tests?
Is there any way to run some hook code before each test, but run it in the "test run " JVM?

The reason for this is that the tests use log4j and produce a large log file.
I’d like to make that log file easier to read by showing a banner on each test.

Thanks in advance,

Connor

Yes you’re right about that. Gradle does currently not offer a way to hook into the testing jvm in the manner you’re looking for. I think the best way to go is to introduce a command abstract test class with the common logic in the setup and teardown methods of the testing framework you use.

cheers,
René

Thanks for the reply, Rene.
I can’t easily do this, it would need many existing test classes splitting from their current superclass.
Is there a place I can request this as a new Gradle feature please?

Thanks,

Connor