JUnit4 compile error 'unexpected token @' on Test assigned to multiple categories


(Sonja Marr) #1

I am working with Geb to build a test suite. I’m currently using spock to define test specs. I’m not a fan of the spock annotations and would rather use the JUnit annotations to declare test categories. I have successfully created a working gradle/spock/JUnit annotation test run, as long as each spec is confined to one category. As soon as I change the @Category(TestA.class) to @Category({TestA.class, TestB.class}) it breaks with an error unexpected token @ on line (first annotated line of the spec).

Any help would be greatly appreciated.

==WORKS==
@Category(SmokeTests.class)
@Test
def “valid local admin should successfully login” () { do stuff }
==/WORKS==
==BROKEN==
@Category({SmokeTests.class, SanityTests.class})
@Test
def “valid local admin should successfully login” () { do stuff }
==/BROKEN==

Both of the implemetation lines for the test interfaces are declared. I also have smokeTest and sanityTest tasks in the build.gradle file. As stated above, I have successfully run individual tasks where specA is assigned to SmokeTests and specB is assigned to SanityTests and the proper tests are picked up. It’s only when attempting to add a test to multiple categories when things go wrong. If I swap the @Test and @Category lines, the same error is thrown, but it always references the first annotated line.

Error:
unexpected token: @ @ line 22, column 3. @Category({SmokeTests.class, SanityTests.class})

Top of stack trace:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:compileTestGroovy’.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:61)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:45)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:233)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)