0

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.

4

1 回答 1

3

您可以使用 afterSuite 并检查带有 null 父级的套件。这是根套件:

test{
    afterSuite{descr, result ->
        if(desc.parent == null){
            //put your logic here
        }
    }
}

希望有帮助,

干杯,勒内

于 2013-07-26T00:53:42.627 回答