【问题标题】:Cucumber Scenario Outline not working with Junit 4.11 and Cucumber 1.2.5Cucumber Scenario Outline 不适用于 Junit 4.11 和 Cucumber 1.2.5
【发布时间】:2017-11-17 07:24:23
【问题描述】:

我正在用黄瓜中的示例表尝试场景大纲。 但是会抛出异常。 cucumber.runtime.CucumberException:无法创建场景运行器 我尝试了各种版本的 Junit 和 cucumber。任何人都可以建议与黄瓜一起使用的正确版本的junit,这样就可以了。其他黄瓜选项都可以正常工作。我也使用了 junit 4.12 和 cucumber 1.2.5,但就 Scenario Outline 而言毫无用处。

【问题讨论】:

  • 请同时包含您尝试运行的场景大纲和用于触发测试的类。我已经将这些版本的 JUnit 和 Cucumber 与 Scenario Outlines 一起使用,从未遇到过问题。
  • 场景大纲:将两个数字相加 给定数字“”和“” 当这两个相加时结果是“” 示例:|one|two|three| |3|4|7|我也试过在占位符中不带引号......它在 ExamplesRunner 类中引发异常
  • 使用您的功能文件或其中的 sn-p 更新您的问题,以便我们可以正确查看它。解读评论可能会导致正确的结果,因为场景大纲确实有效,即使在旧版本的 Cucumber 中也是如此。我目前的猜测是您的问题可能是语法问题。
  • @user8867007 也请分享跑步者类的代码。
  • 我使用 junit-4.12.jar 就好了。见How to create a Minimal, Complete, and Verifiable example

标签: java cucumber junit4 cucumber-java cucumber-junit


【解决方案1】:

你应该看看异常的原因。正如code which throws the exception 所述,原因是用于构造CucumberException

} catch (InitializationError e) {
    throw new CucumberException("Failed to create scenario runner", e);
}

例如,如果您的课程 runner.Runner 不是 public class,则生成的异常消息将如下所示

java.lang.Exception: The class runner.Runner is not public.

edit:这个例子是用 JUnit 4.12 完成的。 JUnit 4.11 和 4.12 中的检查不同。所以这不会在 JUnit 4.11 中引发异常。

JUnit 4.11 案例可能是错误的CucumberOption

cucumber.runtime.CucumberException: Unknown option: --wrong-option

我相信异常消息中会有更多解释。最好是您提供跑步者课程的代码。

【讨论】:

    【解决方案2】:

    我尝试了许多版本的 Junit 和 cucumber。经过 2-3 小时的努力,我终于能够创建测试运行器。 使用以下依赖项。这种组合对我有用

    <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.4.0</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.0.14</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.0.14</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.0.14</version>
    </dependency>
    

    【讨论】:

      【解决方案3】:

      在您的项目中使用这些依赖项,对我来说它工作正常。

      <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-java</artifactId>
         <version>3.0.1</version>
       </dependency>
       <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
       <version>4.12</version>
            <scope>test</scope>
          </dependency>
          <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-java8</artifactId>
              <version>1.2.5</version>
              <scope>test</scope>
          </dependency>
          <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-java</artifactId>
              <version>1.2.5</version>
              <scope>test</scope>
          </dependency>
          <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-junit</artifactId>
              <version>1.2.5</version>
              <scope>test</scope>
          </dependency>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-12-15
        • 1970-01-01
        • 1970-01-01
        • 2020-07-03
        • 1970-01-01
        • 1970-01-01
        • 2017-12-18
        相关资源
        最近更新 更多