How to run spock test from command line?

旧巷老猫 提交于 2019-12-08 02:18:23

问题


I have checked this link:

https://gist.github.com/ysb33r/5825457

It seems like that it can be run like this:

groovyc *.groovy

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

And I have added all third part jars to CLASSPATH,so all imports from these libs found.But all my own classes can't be found,and error message like this:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
LoginTest.groovy: 11: unable to resolve class com.vsi.icareos.client.home.HomePage
@ line 11, column 1.
import com.vsi.icareos.client.home.HomePage
^

LoginTest.groovy: 22: unable to resolve class LoginByPwdPage 
@ line 22, column 2.
LoginByPwdPage loginPage
^

LoginTest.groovy: 35: unable to resolve class LoginByPwdPage 
     @ line 35, column 13.
       loginPage=new LoginByPwdPage(browser,Consts.PAGE_ID)
          ^
3 errors

I guess that the option like:--sourcepath is needed,but I found this command option deprecated,so How to slove this problem?


回答1:


I was able to run the tests described in the gist, but with modification of the groovyc to add the -cp flag with spock jar to it, also if you have the sources in sub-directories you should use **/*.groovy instead of *.groovy

Looking at the way you run the java command, it seams to be missing a space between . and org.junit.runner.JUnitCore

So instead of

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

I should be

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

Please note the space in the second. The . is the current directory added to the classpath

hope this helps



来源:https://stackoverflow.com/questions/41892962/how-to-run-spock-test-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!