【问题标题】:The Cucumber JVM's (Groovy) "World (Hooks)" object mixin and Intellij navigationCucumber JVM 的 (Groovy) “世界 (Hooks)” 对象混合和 Intellij 导航
【发布时间】:2018-09-28 01:33:09
【问题描述】:

我正在 intellij 中使用 Cucumber JVM (Groovy) 开发黄瓜场景。我必须说,事情比在 eclipse 中做同样的事情要好得多。

我想解决一个小问题,让我的团队做得更好。但是由于我是 Intellij 的新手,所以我需要以下帮助:

  • 当我在 step def 文件 (groovy) 中时,Intellij 似乎看不到黄瓜“World”对象中定义的变量和方法。因此,对于那些有点烦人的东西,不要获得 IDE 支持(自动完成等)。我该如何解决?

【问题讨论】:

    标签: groovy intellij-idea cucumber-jvm


    【解决方案1】:

    IntelliJ IDEA 期望 一个对象 在 World 闭包中。因此,您可以在每个步骤定义文件中定义以下块:

    World {
        new MockedTestWorld()
    }
    

    MockedTestWorld.groovy:

    class MockedTestWorld implements TestWorld {
        @Lazy
        @Delegate
        @SuppressWarnings("GroovyAssignabilityCheck")
        private TestWorld delegate = {
            throw new UnsupportedOperationException("" +
                "Test world mock is used ONLY for syntax highlighting in IDE" +
                " and must be overridden by concrete 'InitSteps.groovy' implementation.")
        }()
    }
    

    为了清理重复的世界定义,我们使用最后胶水初始化器和一些复制粘贴:

    real/InitSteps.groovy

    def world
    GroovyBackend.instance.@worldClosures.clear()
    GroovyBackend.instance.registerWorld {
        return world ?: (world = new RealTestWorld1()) // Actual initialization is much longer
    }
    

    legacy/InitSteps.groovy

    def world
    GroovyBackend.instance.@worldClosures.clear()
    GroovyBackend.instance.registerWorld {
        return world ?: (world = new LegacyTestWorld1())
    }
    

    最后,运行配置是这样的(使用不同的胶水):

    // Real setup
    glue = { "classpath:test/steps", "classpath:test/real", },
    
    // Legacy setup
    glue = { "classpath:test/steps", "classpath:test/legacy", },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 2021-03-24
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      相关资源
      最近更新 更多