Sto provando a impostare un progetto di esempio per il dialetto Java8 di Cucumber. Il mio problema è che non riesco a farlo funzionare. Ho sempre trovato la seguente gerarchia di eccezioni:Ottiene sempre l'eccezione "Tipo errato all'indice di pool costante" con 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
non ho idea perché ottengo questo errore né come risolvere il problema.
Ho impacchettato tutto in un progetto Maven. Il layout è così:
./src/test/java/soy/wimmer/CucumberIT.java
./src/test/java/soy/wimmer/CucumberStepdefs.java
./src/test/resources/cucumber/cucumber-java8.feature
./pom.xml
Le dipendenze includo nel pom.xml sono:
<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>
Inoltre l'pom.xml carica solo il compilatore e il plugin failsafe.
La mia definizione di 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 {
}
La mia definizione caratteristica:
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
E questo sono i miei definizioni step:
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();
});
}
}
Qualsiasi idea di quello che sto facendo sbagliato qui?
Bene, il messaggio di eccezione non ha il tipo effettivo, ma suppongo che sia tipo '18' e [questa risposta] (http://stackoverflow.com/a/23625762/2711488) si applica. In breve, sembra che Cucumber non sia adatto a Java 8, infatti, non è nemmeno compatibile al 100% con Java 7 quindi ... – Holger
Potrebbe essere un Invokedynamic perché ci sono espressioni lambda nel costruttore della classe. Ma ho configurato il compilatore per l'origine e la versione di destinazione 1.8 nel pom.xml e sono le definizioni di passo e quindi una classe compilata localmente, no? –
Come detto nella risposta collegata, il problema è * non * il compilatore.Il problema è che esiste uno strumento * runtime * che tenta di elaborare il file di classe compilato, ovvero bytecode. Guarda il metodo che getta "IllegalArgumentException". – Holger