Last active
June 26, 2023 23:43
-
-
Save ysb33r/5825457 to your computer and use it in GitHub Desktop.
Running Groovy unittests from the command-line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example { | |
def hhg() { 42 } | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spock.lang.* | |
class ExampleSpec extends Specification { | |
def "It must be 42" () { | |
def ex = new Example() | |
expect: | |
ex.hhg() == 6*9 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.* | |
import org.junit.* | |
class ExampleTest { | |
@Test | |
void isIt42() { | |
def ex = new Example() | |
assertTrue ex.hhg() == 6*9 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compile the groovy code | |
groovyc *.groovy | |
# Running a JUnit4 test | |
java -cp $GROOVY_HOME/embeddable/groovy-all-2.1.4.jar:$GROOVY_HOME/lib/junit-4.11.jar:$GROOVY_HOME/lib/hamcrest-core-1.3.jar:. \ | |
org.junit.runner.JUnitCore ExampleTest | |
# Download Spock if you don't have it | |
grape install org.spockframework spock-core 0.7-groovy-2.0 | |
# Running a Spock class | |
java -cp ~/.grapes/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar:$GROOVY_HOME/embeddable/groovy-all-2.1.4.jar:$GROOVY_HOME/lib/junit-4.11.jar:$GROOVY_HOME/lib/hamcrest-core-1.3.jar:. \ | |
org.junit.runner.JUnitCore ExampleSpec |
Ok. Thanks. I now have something that works.
groovyc *.groovy
if [ $? -eq 0 ]; then
groovy HikerSpec
fi
But it still hard-wires the name HikerSpec.
Do you know if that can be fixed?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@grab doesn't have to use a network if you have some local cache/repo. You can also add spock jar(s) to a ${user.home}/.groovy/lib or ${groovy.home}/lib directory.