Search code examples
eclipsegroovyannotationssharedspock

Getting error in eclipse for spock's @Shared annotation


As a try, I created a simple groovy class in eclipse and wrote a simple spock test method. I created one object with @Shared annotation and eclipse is complaining like:

Multiple markers at this line
- Groovy:unable to resolve class Shared , unable to find class 
 for annotation
- Groovy:class Shared is not an annotation in @Shared

I googled a little but did not find the solution. Does anyone know why this error is occurring? Below is the sample code:

class SimpleSpockTestExampleSpec extends Specification {

   @Shared
   MyObject obj;

   def "length of Spock's and his friends' names"()
   {
      expect:"Replaces when-then block"
      name.size() == length

      where:
      name << ["zzzzz","xxx","yyy"]
      length << [5,6,7]
   }    
}

enter image description here

Pease ignore the line numbers in the image.


Solution

  • It seems that you haven't imported appropriate package. Do you have the following statement in the code:

    import spock.lang.Shared
    

    ?