Programatic run of Spock

16 views
Skip to first unread message

Russel Winder

unread,
Sep 13, 2011, 9:47:12 AM9/13/11
to Spock Users
I may be missing something really obvious, but
http://code.google.com/p/spock/wiki/GettingStarted does not mention how
to run a Spock job from a Groovy script. The context is that of
creating a Spock program as a string in a Groovy script and then
compiling and running it from within the script. Using GroovyShell
requires an explicit main, but what to put in that main?

Thanks.

--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@russel.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder

signature.asc

Luke Daley

unread,
Sep 13, 2011, 9:55:15 AM9/13/11
to spockfr...@googlegroups.com

On 13/09/2011, at 2:47 PM, Russel Winder wrote:

> I may be missing something really obvious, but
> http://code.google.com/p/spock/wiki/GettingStarted does not mention how
> to run a Spock job from a Groovy script. The context is that of
> creating a Spock program as a string in a Groovy script and then
> compiling and running it from within the script. Using GroovyShell
> requires an explicit main, but what to put in that main?

You can use the grails plugin for inspiration:

https://github.com/spockframework/spock-grails/blob/master/spock-grails-support/src/main/groovy/grails/plugin/spock/test/GrailsSpecTestType.groovy#L63

Basically you through the classes at http://junit.sourceforge.net/javadoc/org/junit/runner/JUnitCore.html

Benjamin Gudehus

unread,
Dec 23, 2011, 1:52:06 PM12/23/11
to spockfr...@googlegroups.com
You may run groovy scripts with a spock specification with GroovyShell.run().
Or directly with JUnit4Utils.realRunJUnit4Test(scriptClass, scriptLoader).

def shellSpock = new GroovyShell()
shellSpock.loader.addClasspath("lib/junit-4.8.2.jar")
shellSpock.loader.addClasspath("lib/spock-core-0.5-groovy-1.7.jar")
//shellSpock.loader.parseClass(new File("scripts/ScriptSpock2.groovy"))
shellSpock.run(new File("scripts/ScriptSpock1.groovy"))

def scriptLoader = shellSpock.loader
def scriptFile = new File("scripts/ScriptSpock1.groovy")
def scriptClass = AccessController.doPrivileged(new PrivilegedExceptionAction<Class>() {
    Class run() {
        return scriptLoader.parseClass(scriptFile)
    }
})
JUnit4Utils.realRunJUnit4Test(scriptClass, scriptLoader)


2011/9/13 Luke Daley <lda...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To post to this group, send email to spockfr...@googlegroups.com.
To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.


Reply all
Reply to author
Forward
0 new messages