Cucumber Scenario Outline不使用Junit 4.11和Cucumber 1.2.5

时间:2017-11-17 07:24:23

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

我正在尝试使用黄瓜示例表的场景大纲。 但抛出异常。 cucumber.runtime.CucumberException:无法创建场景运行器 我尝试了各种版本的Junit和黄瓜。任何人都可以建议正确版本的junit与黄瓜一起使用,以便这样做。其他黄瓜选项工作正常,除此之外。我已经使用了junit 4.12和黄瓜1.2.5,但就场景大纲而言没有用。

3 个答案:

答案 0 :(得分:0)

您应该查看异常的原因。正如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.

编辑:这个例子是用JUnit 4.12完成的。 JUnit 4.11和4.12中的检查不同。所以这不会在JUnit 4.11中抛出异常。

JUnit 4.11案例可能是错误的CucumberOption

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

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

答案 1 :(得分:0)

我尝试了许多版本的Junit和黄瓜。经过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>

答案 2 :(得分:0)

在您的项目中使用这些依赖关系,对我来说一切正常。

<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>