0

出于某种原因,我的代码只会在使用一种格式化程序时运行。

@RunWith(Cucumber.class)
@Cucumber.Options(features={"src/test/resources/cucumber"}, glue={"cucumber.com.zzz.yyy.steps"}, format={"html:target/test-reports"})
public class RunCucumberTest {

}

如果我添加另一个:

format={"pretty","html:target/test-reports"}

我得到一个 IndexOutOfBoundsException:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:604)
    at java.util.ArrayList.get(ArrayList.java:382)
    at gherkin.formatter.PrettyFormatter.indentedLocation(PrettyFormatter.java:142)
    at gherkin.formatter.PrettyFormatter.printStep(PrettyFormatter.java:255)
    at gherkin.formatter.PrettyFormatter.match(PrettyFormatter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

如果我添加另一个:

format={"pretty","html:target/test-reports", "json:target/test-reports/cucumber.json"}

这次我得到另一个 IndexOutOfBoundsException = -1:

java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(ArrayList.java:371)
    at java.util.ArrayList.get(ArrayList.java:384)
    at gherkin.formatter.JSONFormatter.getFeatureElement(JSONFormatter.java:199)
    at gherkin.formatter.JSONFormatter.addHook(JSONFormatter.java:156)
    at gherkin.formatter.JSONFormatter.before(JSONFormatter.java:147)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at cucumber.runtime.Utils$1.call(Utils.java:44)
    at cucumber.runtime.Timeout.timeout(Timeout.java:12)
    at cucumber.runtime.Utils.invoke(Utils.java:40)
    at cucumber.runtime.RuntimeOptions$2.invoke(RuntimeOptions.java:138)
    at com.sun.proxy.$Proxy12.before(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.before(JUnitReporter.java:129)
    at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:208)
    at cucumber.runtime.Runtime.runHooks(Runtime.java:185)
    at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:175)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:32)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:83)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:77)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:82)

谁能帮我弄清楚这是怎么回事!!!!?

版本:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <scope>test</scope>
     <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <scope>test</scope>
     <version>1.1.3</version>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <scope>test</scope>
    <version>1.1.3</version>
</dependency>
4

1 回答 1

0

添加jvm依赖:

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-jvm</artifactId>
    <version>1.1.5</version>
    <type>pom</type>
</dependency>

一切运行正常。

于 2013-10-01T12:17:15.197 回答