【问题标题】:Import cucumber step definitions of one module into another maven module将一个模块的黄瓜步骤定义导入另一个 maven 模块
【发布时间】:2022-01-19 12:24:39
【问题描述】:

我有以下带有 Junit 和 Cucumber 的 Maven 项目结构:

| root project
    | Module 1
         | src
             | main
             | test
                 | java
                     | tests // where all step definitions from Module 1 are stored
             | resources
                 | features // feature files from Module 1
    | Module 2
         | src
             | main
             | test
                 | java
                     | tests // where all step definitions from Module 2 are stored
             | resources
                 | features // feature files from Module 2

我想在模块 2 中重复使用模块 1 中的步骤。是否可以将模块 1 中的步骤定义导入到模块 2 中以在那里重复使用它们?

【问题讨论】:

  • 是的,这是可能的。取决于您是否已经自己进行了一些试验?
  • 是的,我尝试将 Module1 添加为 Module2 的依赖项,并在黄瓜运行器类中设置“胶水”,但它仍然抛出“UndefinedStepException”异常。另外,我在其他地方发现,将步骤定义导出到单独的 jar 文件中可能会有所帮助,但不确定这是否是正确的方法。

标签: java maven cucumber


【解决方案1】:

您已经在做的是一种正确的方法。您需要考虑以下几点:

  1. 由于您的 Step Defs 位于 test 中,因此不会传递地参与 module2 类路径
  2. 还要确保 module1 中的 step defs 与您的module2 具有正确的包关系:module2 中的 runner 类与位于同一包中的功能文件位于同一包或更高版本中,或者高于您的步骤定义类
  3. 确保 module2 具有 module1 作为依赖项

因此,要修复示例中的第 1 点,您需要将 module1 中的步骤定义从 test 移动到 main

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-15
  • 2022-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-23
相关资源
最近更新 更多