0

I would like to execute some additional script steps after each test run. So basically, I would like to create a new script in grails which

  • first calls the standard test-app functional:webtest -baseUrl=http://example.com
  • afterwards runs some kind of clean-up script

Now I wonder about how to call the test-appscript from within my script...

rdmueller
  • 10,742
  • 10
  • 69
  • 126

2 Answers2

3

The common way to do that is shown in this example:

scriptEnv = "test"

includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsClean")
includeTargets << grailsScript("_GrailsTest")


target(main: "Testing app (unit coverage)") {
    echo "Testing app (unit coverage)"

    argsMap << ["unit":'']
    argsMap << ["coverage":'']
    phasesToRun = ['unit']

    allTests()
}

setDefaultTarget(main)

The line grailsScript("_GrailsInit") does the trick and inlcudes the targets of the grails scripts into the own.

You can have a look at this http://grails.org/doc/latest/guide/commandLine.html#creatingGantScripts

matcauthon
  • 2,261
  • 1
  • 24
  • 41
1

You'll need to use the execute.shell command like so:

includeTool << gant.tools.Execute

target(main: "Run script") {
    execute.shell("grails test-app functional:webtest -baseUrl=http://example.com")
    //Proceed with cleanup code here...
}

See http://gant.codehaus.org/Execute+Tool for more information.

Michael D Johnson
  • 889
  • 1
  • 10
  • 21
  • Is this really the right way? There should be a better way to start one script from within another. Your solution will start grails twice... – rdmueller Aug 06 '12 at 21:11
  • There is a better way to run another gant script, but to run a Grails task I have not found a better way I'm afraid. I could be wrong, but this is the only solution I've found. A 'better' way would probably be to write an inline plugin, the amount of effort required needs to be balanced against your ultimate goal. In my case, I wanted a quick an easy way to execute another grails plugin from the command line. This was the solution I found. – Michael D Johnson Aug 07 '12 at 15:30
  • I wonder if this will start another Grails environment with another JVM and everything... – Sergey Orshanskiy Oct 16 '13 at 03:32
  • My original answer is based on outdated code. I believe that matcauthon's answer is the correct one today. – Michael D Johnson Oct 17 '13 at 16:12