How to force gradle to restart the main JVM thread before each junit test


(willbdaniels) #1

This problem is specifically linked to using Gradle with javafx, testFX for the gui testing integration, and Junit for the actual unit tests.

The problem is that due to the nature of our particular test suite requires the application to restart and the automated tests to run through EVERY stage of the applications life cycle for every single junit test class. Due to this requirement, when gradle runs multiple tests, it tries to call my launchApplication() method multiple times under the same instance of the jvm, which gives the error:

Exception in thread "thread-10" java.lang.IllegalStateException: Application launch must not be called more than once

I’m fairly certain I can solve this problem with making every individual class a testSuite and then using the @category tag, but considering I have over 100 various classes that all require this sort of setup, it would be more than a little cumbersome. So, is there any way to force gradle to do a full restart of the jvm between unit test classes? or am I (for now) limited to the above solution, or trying to find a different way around it?

here is the stack trace after running gradlew test --info, keep in mind i DID try to run this without the daemon, with the same results.

you can see the stack trace here: http://pastebin.com/CLsxFVWY


(Peter Niederwieser) #2
test {
    forkEvery = 1
}

Be aware that this will slow down test execution significantly.


(willbdaniels) #3

Thank you Peter! I do realize that this will significantly slow down the tests, but seeing as how they run overnight on a dedicated test and release machine anyway, speed is of little concern.

Cheers!

-William Daniels

P.S. if you ever need help building javafx with gradle, shoot me an e-mail, I have a 40+ file project with .DLL’s, and the whole kaboodle building against gradle.