How to run final code at the end of the test

Summary

Normally, clean up code should be part of tearDown testcases. However, is some situations, you may need to run some final code at the end of the test after the results have been tabulated. This is easy to do with a final target. A specific example is How to run Selenium as a GINT test.

Example
@Grab(group='org.swift.tools', module='gint', version='2.7.0')
import org.swift.tools.*
includeTool << Gint

gint.initialize(this) // required

gint.add(
    name: 'hello', 
    inline: { println 'Hello World' },
)
 
target(name: 'final', description: 'Run this last', prehook: [], posthook: []) {
    message 'info', 'Final code gets run here'
}
 
gint.finalizeTest() // final preparations for running tests

Output
gant -f helloworld 

    [start] hello
Hello World
   [ending] hello
 [complete] hello - 0.01 secs

     [info] Successful testcases  . . . . . . . . . . : 1    <<< TEST SUCCESSFUL
     [info] Total testcases . . . . . . . . . . . . . : 1
     [info] Elapsed run time  . . . . . . . . . . . . : 0.684 secs 
= = = = = =   helloworld completed at Wed Sep 12 07:41:21 CDT 2012 = = = = = =
     [info] Final code gets run here
BUILD SUCCESSFUL
Total time: 1.78 seconds