CucumberのJava8方言のサンプルプロジェクトをセットアップしようとしています。私の問題は、私はそれが実行されないことです。私はこのエラーを取得したりどのようにそれを修正するために、なぜ私は見当がつかないCucumber-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.<init>(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.<init>(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に含める依存関係は、次のとおりです。
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
はまたの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();
});
}
}
私がやっているすべてのアイデアここで間違っている?
例外メッセージには実際のタイプはありませんが、タイプは「18」で、[この回答](http://stackoverflow.com/a/23625762/2711488)が適用されます。要するに、CucumberはJava 8には適していないようですが、実際にはJava 7と100%互換ではありません。 – Holger
クラスのコンストラクタにラムダ式があるため、Invokedynamicかもしれません。しかし、私はコンパイラをpom.xmlのソースとターゲットバージョン1.8に設定しました。これはステップ定義なので、ローカルでコンパイルされたクラスですか? –
リンクされた答えで述べたように、問題はコンパイラではなく*です。問題は、コンパイルされたクラスファイル、別名バイトコードを処理しようとする*ランタイム*ツールがあることです。 'IllegalArgumentException'をスローするメソッドを見てください。 – Holger