当前位置: 首页 > 工具软件 > cucumber-api > 使用案例 >

java8 常量池_java-8 – 始终使用Cucumber-Java8获取异常“常量池索引的错误类型”...

卓新知
2023-12-01

我正在设计一个用于

Java8方言的示例项目.我的问题是,我没有得到它运行.我总是得到以下异常层次结构:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.068 sec <<< FAILURE! - in soy.wimmer.CucumberIT

Feature: Cucumber with Java8 Time elapsed: 0.051 sec <<< ERROR!

cucumber.runtime.CucumberException: Failed to instantiate class soy.wimmer.CucumberStepdefs

[…]

Caused by: java.lang.reflect.InvocationTargetException: null

[…]

Caused by: cucumber.runtime.CucumberException: java.lang.IllegalArgumentException: Wrong type at constant pool index

[…]

Caused by: java.lang.IllegalArgumentException: Wrong type at constant pool index

at sun.reflect.ConstantPool.getMemberRefInfoAt0(Native Method)

at sun.reflect.ConstantPool.getMemberRefInfoAt(ConstantPool.java:47)

at cucumber.runtime.java8.ConstantPoolTypeIntrospector.getTypeString(ConstantPoolTypeIntrospector.java:37)

at cucumber.runtime.java8.ConstantPoolTypeIntrospector.getGenericTypes(ConstantPoolTypeIntrospector.java:27)

at cucumber.runtime.java.Java8StepDefinition.(Java8StepDefinition.java:45)

at cucumber.runtime.java.JavaBackend.addStepDefinition(JavaBackend.java:162)

at cucumber.api.java8.En.Given(En.java:190)

at soy.wimmer.CucumberStepdefs.(CucumberStepdefs.java:8)

[…]

Results :

Tests in error:

Failed to instantiate class soy.wimmer.CucumberStepdefs

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

我不知道为什么我得到这个错误,也不知道如何解决它.

我把所有东西都包装在Maven项目中.布局是这样的:

./src/test/java/soy/wimmer/CucumberIT.java

./src/test/java/soy/wimmer/CucumberStepdefs.java

./src/test/resources/cucumber/cucumber-java8.feature

./pom.xml

我在pom.xml中包含的依赖关系是:

info.cukes

cucumber-java8

1.2.3

test

info.cukes

cucumber-junit

1.2.3

test

junit

junit

4.12

test

另外,pom.xml仅加载编译器和故障安全插件.

我的CucumberIT.java定义:

package soy.wimmer;

import cucumber.api.CucumberOptions;

import cucumber.api.junit.Cucumber;

import org.junit.runner.RunWith;

@RunWith(Cucumber.class)

@CucumberOptions(features = "classpath:cucumber")

public class CucumberIT {

}

我的功能定义:

Feature: Cucumber with Java8

As a developer

I want to use Cucumber-java8

So that I have nicer step definitions

Scenario: Let's try it

Given I have some dummy code

When I try to test it

Then it should work with cucumber-java8

这是我的步骤定义:

package soy.wimmer;

import cucumber.api.PendingException;

import cucumber.api.java8.En;

public class CucumberStepdefs implements En {

public CucumberStepdefs() {

Given("^I have some dummy code$", () -> {

// Write code here that turns the phrase above into concrete actions

throw new PendingException();

});

When("^I try to test it$", () -> {

// Write code here that turns the phrase above into concrete actions

throw new PendingException();

});

Then("^it should work with cucumber-java(\\d+)$", (Integer arg1) -> {

// Write code here that turns the phrase above into concrete actions

throw new PendingException();

});

}

}

任何想法我在这里做错什么?

 类似资料: