在spclipse中获取spock的@Shared注释错误

时间:2016-07-07 03:52:30

标签: eclipse groovy annotations shared spock

试一试,我在eclipse中创建了一个简单的groovy类,并编写了一个简单的spock测试方法。 我创建了一个带有@Shared注释的对象,而eclipse正在抱怨:

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
我用谷歌搜索了一下,但没有找到解决方案。有谁知道为什么会出现这个错误?以下是示例代码:

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忽略图像中的行号。

1 个答案:

答案 0 :(得分:1)

好像你没有导入合适的包。您是否在代码中有以下声明:

import spock.lang.Shared