Spock测试:Eclipse似乎没有识别Where子句中的数据变量

问题描述 投票:0回答:2

我有一个使用where子句的Spock测试。在Eclipse中,测试文件是使用Groovy Editor打开的,但代码(“testName”)和where子句(testNum和testName)中的数据变量都带有下划线。 maven构建工作正常。

有人能让我知道如何在Eclipse中解决这个问题吗?

  @Unroll
  def 'Test #testNum'() {
      def tname = testName

      ......

      where:
         testNum  |  testName
          '1'     | 'test #1'
  }
eclipse groovy spock
2个回答
1
投票

我没有使用Eclipse很长一段时间,但是定义测试参数可能会让Eclipse更加困惑:

@Unroll
def 'Test #testNum'(String testNum, String testName) {

    def tname = testName

    ......

    where:
    testNum  |  testName
    '1'      | 'test #1'
}

0
投票

我可以通过运行Spock转换来删除下划线将此添加到eclipse.ini的末尾:

-Dgreclipse.globalTransformsInReconcile=org.spockframework.compiler.SpockTransform

但是,推断的testName类型是Object(请参阅另一个答案下的评论)。

Eclipse Groovy editor with Spock test

© www.soinside.com 2019 - 2024. All rights reserved.