【问题标题】:@CucumberOptions in cucumber-junit-platform-enginecucumber-junit-platform-engine 中的@CucumberOptions
【发布时间】:2021-02-11 16:44:37
【问题描述】:

我正在尝试将我的黄瓜测试从 cucumber-junit 迁移到 cucumber-junit-platform-engine 以便能够使用新的平台功能。如何重新定义我的跑步者以使用旧的@CucumberOptions。我正在调查这个问题,但似乎还没有找到正确的方法。

在我使用这些选项之前:

@CucumberOptions(
  plugin = ...,
  features = ...,
  tags = ...,
  glue = ...
)

有没有一种直接的方法可以将其迁移到平台引擎?

【问题讨论】:

  • 在我的例子中,要使用plugin 选项,必须在cucumber.properties 中声明它,在src/test/resources 下为cucumber.plugin=<package_under_src_test_java>.<class_name>

标签: java cucumber junit5 cucumber-java cucumber-junit


【解决方案1】:

Junit5/#2416 被合并之前,没有一对一的替换。但是,如果您只有一个使用 @CucumberOptions 注释的类,则向 junit-platform.properties 添加属性就足够了。

【讨论】:

  • 有多跑者的项目呢?我如何定义features = ...,?我找不到新图书馆的此类财产。我将阅读有关测试发现的内容并尝试弄清楚。如果您知道如何操作,我将不胜感激。
  • 您必须使用不同的发现选择器多次启动 JUnit 5。
  • 您可以在 Junit 文档中阅读相关内容。然后你必须将它映射到 Maven/Gradle。 junit.org/junit5/docs/current/user-guide/…
  • 这可能很傻,但我应该把选择器代码放在哪里?假设我在某个目录中有我的功能文件。当我使用@CucumberOptions 时,features=classpath:some/dir 很简单。现在我想我需要使用 URISelector 但我实际上把它放在哪里?
  • 我问了关于featureshere的更具体的问题。
【解决方案2】:

看起来应该使用来自junit-platform-engine@Suite 和适当的引擎来代替黄瓜注释。

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example")
public class RunCucumberTest {
}

向@spmason answer致敬。

【讨论】:

    【解决方案3】:

    过去几天我一直在研究 JUnit5Cucumber 7.0,我只是在添加您自己的答案。 文档稀缺,这个link一直是祝福和docs

    你不必使用@IncludeEngines 还要注意包是如何被引用的

    @Suite
    @SelectClasspathResource("com/rmdaw/cucumber/features")
    @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.rmdaw.repository")
    

    最后一件事你可以将配置放入 test/java/resources/junit-platform.properties 里面你可以有这样的东西:

    cucumber.publish.quiet=true
    cucumber.glue=com.rmdaw.cucumber
    cucumber.plugin=pretty,\
                html:target/SystemTestReports/report.html,\
                json:target/SystemTestReports/report.json,\
                junit:target/SystemTestReports/junit.xml\ 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多