Re: Unable to run HelloSpock with gradle test

990 views
Skip to first unread message

Peter Niederwieser

unread,
Mar 12, 2013, 6:15:45 PM3/12/13
to spockfr...@googlegroups.com
Is the source file containing the spec class located in the correct directory? If the package name is `foo.bar`, then you'll have to put the source file into `src/test/groovy/foo/bar` (assuming you haven't customized the source directories in the Gradle build).

Cheers,
Peter

On Tuesday, 12 March 2013 23:03:48 UTC+1, João Peixoto wrote:
I'm trying out Spock. I looked at the example project, cloned it from git and it runs perfect.

Now I copied the HelloSpec into the project that I want to run Spock on. Through eclipse I can run the test fine with "Run As Junit test" but on the command line, if I do "gradle test" the report generated is empty.

Some info:
Gradle version: Gradle 1.4
HelloSpockSpec.groovy looks exactly like https://github.com/spockframework/spock-example/blob/master/src/test/groovy/HelloSpockSpec.groovy except the package, because eclipse added that automatically (without it running tests from eclipse doesn't seem to work properly)

# gradle -i test
> (...)
:frontend:testClasses UP-TO-DATE
:frontend:test
Skipping task ':frontend:test' as it is up-to-date.
Skipping task ':frontend:test' as it is up-to-date
:frontend:test UP-TO-DATE

This is weird, shouldn't tests be always run? Anyway, if I change the spec somehow I get this

# gradle -i test
> (...)
:frontend:testClasses UP-TO-DATE
:frontend:test
Executing task ':frontend:test' due to:
Input file /<whatever>/frontend/src/test/<some package>/tests/HelloSpockSpec.groovy for task ':frontend:test' has changed.
Finished generating test XML results (0.0 secs)
Generating HTML test report...
Finished generating test html results (0.0060 secs)

This looks good, but the reports generated are empty. No tests were run and I have no idea why.

Thanks in advance for your help.

João Peixoto

unread,
Mar 12, 2013, 7:47:36 PM3/12/13
to spockfr...@googlegroups.com
Thanks Peter!

I have a custom test srcDir, however I didn't know that I had to have a "groovy" dir too (did I miss something in the docs?).

Anyway, I fixed that and now gradle can find the tests. I say find because it doesn't run, It's complaining about something else..

java.lang.AbstractMethodError
	at org.spockframework.runtime.GlobalExtensionRegistry.startGlobalExtensions(GlobalExtensionRegistry.java:105)
	at org.spockframework.runtime.RunContext.start(RunContext.java:62)
	at org.spockframework.runtime.RunContext.get(RunContext.java:160)
	at org.spockframework.runtime.Sputnik.runExtensionsIfNecessary(Sputnik.java:88)
	at org.spockframework.runtime.Sputnik.run(Sputnik.java:61)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:55)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:42)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:71)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
	at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
	at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
	at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
	at java.lang.Thread.run(Thread.java:680)

Peter Niederwieser

unread,
Mar 12, 2013, 7:56:21 PM3/12/13
to spockfr...@googlegroups.com
On Mar 13, 2013, at 12:47 AM, João Peixoto <joao.h...@gmail.com> wrote:

> I have a custom test srcDir, however I didn't know that I had to have a "groovy" dir too (did I miss something in the docs?).

This isn't about Spock, but about Gradle. Without seeing your Gradle build script, I can't say if you got it right.

> Anyway, I fixed that and now gradle can find the tests. I say find because it doesn't run, It's complaining about something else..

You might have multiple Spock versions on your class path(s). Again, this is likely a problem with your Gradle build.

Cheers,
Peter

João Peixoto

unread,
Mar 12, 2013, 8:18:43 PM3/12/13
to spockfr...@googlegroups.com
True, I should have posted it in first place. Here it goes (some lines omited). I attached it due to its size.

Now that you mentioned there being two versions I took a closer look at build.gradle.

    (...)
    testCompile "org.spockframework:spock-core:1.0-groovy-2.0-SNAPSHOT"
    testCompile "org.spockframework:spock-spring:0.7-groovy-2.0"
    (...)

These seem to be incompatible. If I comment out one of them the test runs :)

Once again, thank you very much for your time and help
JP
build.gradle.rtf
Reply all
Reply to author
Forward
0 new messages