要点:
我正在使用Cucumber对Spring Boot应用程序运行一些测试。当我使用“mvn test”执行它时,我的Cucumber测试正常运行,但是当我在“mvn verify”生命周期中执行它时失败。
详细信息:
My Cucumber runner类看起来像这样:
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/resources/features/creditCardSummary.feature"},
glue = {"th.co.scb.fasteasy.step"},
plugin = {
"pretty",
"json:target/cucumber-json-report.json"
}
)
public class CreditCardRunnerTest {
}
当我执行“mvn test”时,我可以在日志中看到在maven spring boot插件实例化Spring Boot实例之前实例化了Cucumber runner:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running CreditCardRunnerTest
@creditcards
Feature: POST /creditcards/summary
As a user, I would like to get basic information, balance and/or last 'n' transactions of a given list of credit cards, so that I can provide the information for further operations.
...........
2016-11-13 07:29:02.704 INFO 14716 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8090 (http)
2016-11-13 07:29:02.721 INFO 14716 --- [ main] t.c.s.fasteasy.step.CreditCardStepdefs : Started CreditCardStepdefs in 13.486 seconds (JVM running for 16.661)
我知道我的Cucumber测试实际上是一个集成测试,因此我将其作为“mvn verify”生命周期阶段的一部分运行,而不是将其重命名为CucumberRunnerIT.java并按如下方式配置pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
<excludes>
<exclude>**/IT.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>${failsafeArgLine}</argLine>
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
当我将其作为“验证”的一部分运行时,我收到以下错误:
2016-11-13 07:39:42.921 INFO 12244 --- [lication.main()] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2016-11-13 07:39:43.094 INFO 12244 --- [lication.main()] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8090 (http)
2016-11-13 07:39:43.099 INFO 12244 --- [lication.main()] th.co.scb.fasteasy.Application : Started Application in 10.41 seconds (JVM running for 52.053)
[INFO]
[INFO] --- maven-failsafe-plugin:2.19.1:integration-test (default) @ creditcards ---
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running CreditCardRunnerIT
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.716 sec <<< FAILURE! - in CreditCardRunnerIT
initializationError(CreditCardRunnerIT) Time elapsed: 0.008 sec <<< ERROR!
cucumber.runtime.CucumberException: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
Results :
Tests in error:
CreditCardRunnerIT.initializationError ▒ Cucumber java.lang.ArrayStoreExceptio...
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] --- maven-failsafe-plugin:2.19.1:integration-test (integration-tests) @ creditcards ---
我注意到因为我在预集成测试期间设置了maven spring-boot插件,所以在Cucumber初始化之前执行它但我不确定这是否是错误。我确实尝试配置spring-boot插件以在“集成测试”期间启动应用程序而不是“预集成测试”,但它似乎没有做太多。
关于我在这里做错了什么想法?
答案 0 :(得分:-1)
这是与jdk版相关的问题。如果您使用JDK 1.8.0u51,那么它将被解决。
如果您的jdk版本较高,则会出现此问题。 所以请使用JDK 1.8.0u51或更低版本。
更多信息,您可以解决此问题。这与您的问题相同:https://github.com/cucumber/cucumber-jvm/issues/912