如何从命令行运行spock测试? [英] How to run spock test from command line?
问题描述
我检查了此链接:
https://gist.github.com/ysb33r/5825457
好像它可以像这样运行:
groovyc * .groovy
java -cp〜/ .grapes / org.spockframework / spock-core / jars / spock-core -0.7-常规-2.0.jar:$ GROOVY_HOME /嵌入/ Groovy的全2.1.4.jar:$ GROOVY_HOME / lib中/ JUnit的-4.11.jar:$ GROOVY_HOME / lib目录/ hamcrest核-1.3.jar:.ORG .junit.runner.JUnitCore ExampleSpec
我已经将所有第三部分jar添加到CLASSPATH中,从这些libs found.But所有我自己的类不能被发现,并像这样的错误消息:
$ $ p $ org.codehaus。 groovy.control.MultipleCompilationErrorsException:启动失败:
LoginTest.groovy:11:无法解析类com.vsi.icareos.client.home.HomePage
@ line 11,column 1.
import com.vsi.icareos.client.home.HomePage
^
LoginTest.groovy:22:无法解析类LoginByPwdPage
@ line 22,第2列。
LoginByPwdPage loginPage
^
LoginTest.groovy:35:无法解析class LoginByPwdPage
@ line 35,column 13.
loginPage = new LoginByPwdPage(browser,Consts.PAGE_ID)
^
3 errors
我猜这样的选项是: - sourcepath是必需的,但我发现这个命令选项已被弃用,所以如何解决这个问题?
我能够运行在要点中描述的测试,但修改了 groovyc
使用spock jar将 -cp
标志添加到它,如果你在子目录中有源代码,你应该使用 ** / * .groovy
代替 *。groovy
观察运行 java
命令,它会在缺少。
和 org.junit.runner之间的空格。 JUnitCore
因此,而不是
java -cp〜/ .grapes / org.spockframework / spock-core / jars /斯波克核心 - 0.7 - 常规 - 2.0.jar:$ GROOVY_HOME /嵌入/ Groovy的全2.1.4.jar:$ GROOVY_HOME / lib中/ JUnit的-4.11.jar:$ GROOVY_HOME / lib目录/ hamcrest核-1.3.jar :.org.junit.runner.JUnitCore ExampleSpec
我应该是
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 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?
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
这篇关于如何从命令行运行spock测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!