My current test task looks like this:
test {
doFirst {
println 'Starting application...'
Thread.startDaemon {
appProcess = testServerExec.execute()
}
sleep 20000 // wait for thread to start
}
doLast {
appProcess.destroy()
}
}
I've noticed that if the tests pass, appProcess.destroy()
is called and everyone's happy. However, if the tests fail, the thread lingers and I have to kill the process myself. I know Gradle has a try/finally, but I'm not sure how to use that correctly in this case. Basically, I want appProcess.destroy()
to run, even if tests fail.
How might I go about it?
Edit: Discovered beforeSuite
and afterSuite
, but I run multiple suites of tests and I only want this thread started before all suites, and killed after all suites.