gpt4 book ai didi

java - Spring Boot 的 Cucumber 测试可以在 "mvn test"中运行,但不能在 "mvn verify"中运行

转载 作者:搜寻专家 更新时间:2023-11-01 00:58:38 29 4
gpt4 key购买 nike

总结:

我正在使用 Cucumber 针对 Spring Boot 应用程序运行一些测试。当我使用“mvn test”执行它们时,我的 Cucumber 测试运行良好,但当我在“mvn verify”生命周期中执行它们时失败。

详细信息:

我的 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 插件以在“集成测试”期间启动应用程序而不是“预集成测试”,但它似乎并没有做太多。

关于我在这里做错了什么有什么想法吗?

最佳答案

这是jdk版本相关的问题。如果你用JDK 1.8.0u51,那就解决了。

如果你的jdk版本较高,那么就会出现这个问题。所以请使用JDK 1.8.0u51或更低版本。

更多内容,大家可以过这个issue。与您的问题相同:https://github.com/cucumber/cucumber-jvm/issues/912

关于java - Spring Boot 的 Cucumber 测试可以在 "mvn test"中运行,但不能在 "mvn verify"中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40569343/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com