简体   繁体   English

Cucumber Scenario Outline 不适用于 Junit 4.11 和 Cucumber 1.2.5

[英]Cucumber Scenario Outline not working with Junit 4.11 and Cucumber 1.2.5

I am trying Scenario outline with example table in cucumber.我正在尝试使用黄瓜示例表的场景大纲。 But an exception is thrown.但是会抛出异常。 cucumber.runtime.CucumberException: Failed to create scenario runner I tried it with various versions of Junit and cucumber. Cucumber.runtime.CucumberException: 无法创建场景运行程序我尝试使用各种版本的 Junit 和 Cucumber。 Can anyone suggest the correct version of junit to use with cucumber so that this works.Other cucumber options are working fine exceot this.任何人都可以建议与黄瓜一起使用的正确版本的junit,以便它起作用。其他黄瓜选项工作正常,但它除外。 I have used junit 4.12 and cucumber 1.2.5 as well but of no use as far as Scenario Outline is concerned.我也使用过junit 4.12 和cucumber 1.2.5,但就Scenario Outline 而言没有用。

You should have a look on the reason of the exception.您应该查看异常的原因。 As the code which throws the exception states that the cause is used to construct the CucumberException由于引发异常代码指出原因用于构造CucumberException

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

If for example your class runner.Runner would not be a public class the resulting exception message would look like例如,如果您的类runner.Runner不是public class则生成的异常消息将如下所示

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

edit: This example was done with JUnit 4.12.编辑:这个例子是用 JUnit 4.12 完成的。 The checks are different in JUnit 4.11 and 4.12. JUnit 4.11 和 4.12 中的检查是不同的。 So this does not throw an exception in JUnit 4.11.所以这不会在 JUnit 4.11 中抛出异常。

a JUnit 4.11 case could be a wrong CucumberOption . JUnit 4.11 案例可能是错误的CucumberOption

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

I believe there would be some more explanation in the exception message.我相信异常消息中会有更多解释。 Best would be you provide the code for your runner class.最好是你为你的跑步者课程提供代码。

I tried many version of Junit and cucumber.我尝试了很多版本的 Junit 和黄瓜。 after 2-3 hrs of struggle I was finally able to create the test runner.经过 2-3 小时的努力,我终于能够创建测试运行程序。 Use below dependencies.使用以下依赖项。 This combination worked for me这种组合对我有用

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

Use these dependencies in your project, for me it is working fine.在您的项目中使用这些依赖项,对我来说它工作正常。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM