简体   繁体   English

Spring Boot的黄瓜测试可以在“mvn test”中运行,但不能在“mvn verify”中运行

[英]Cucumber test for Spring Boot can run in “mvn test” but not in “mvn verify”

Summary: 摘要:

I am running some tests using Cucumber against a Spring Boot application. 我正在使用Cucumber对Spring Boot应用程序运行一些测试。 My Cucumber test are running fine when I execute them using "mvn test" but fails when I execute them in the "mvn verify" lifecycle. 当我使用“mvn test”执行它们时,我的Cucumber测试正常运行,但是当我在“mvn verify”生命周期中执行它时失败。

Details: 细节:

My Cucumber runner class looks like this: 我的Cucumber跑步者类看起来像这样:

@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 {

}

when I execute "mvn test", I can see in the logs that the Cucumber runner is instantiated before the maven spring boot plugin instantiates the Spring Boot instance: 当我执行“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)

I know that my Cucumber test is actually an integration test so I move it to run as part of the "mvn verify" lifecycle phase instead by renaming it to CucumberRunnerIT.java and configuring the pom.xml as follows: 我知道我的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>

When I run it as part of "verify" though, I get the following error: 当我将其作为“验证”的一部分运行时,我收到以下错误:

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 ---

I noticed that because I had set maven spring-boot plugin to run during pre-integration-test, it is executed before Cucumber is initialized but I'm not sure if this is the error. 我注意到因为我在预集成测试期间设置了maven spring-boot插件,所以在Cucumber初始化之前执行它但我不确定这是否是错误。 I did try to configure spring-boot plugin to start the app during "integration-test" instead of "pre-integration-test" but it didn't seem to do much. 我确实尝试配置spring-boot插件以在“集成测试”期间启动应用程序而不是“预集成测试”,但它似乎没有做太多。

Any ideas on what I'm doing wrong here? 关于我在这里做错了什么的想法?

This is jdk version related issue. 这是jdk版本相关的问题。 If you use JDK 1.8.0u51, then it will be solved. 如果您使用JDK 1.8.0u51,那么它将被解决。

If your jdk version is higher, then this problem will occur. 如果您的jdk版本较高,则会出现此问题。 So please use JDK 1.8.0u51 or lower version. 所以请使用JDK 1.8.0u51或更低版本。

For more, you can go through this issue. 更多信息,您可以解决此问题。 It is same to your issue: https://github.com/cucumber/cucumber-jvm/issues/912 它与您的问题相同: https//github.com/cucumber/cucumber-jvm/issues/912

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “mvn 测试” 0 次测试运行 - spring + cucumber + junit5 - "mvn test" 0 tests run - spring + cucumber + junit5 如何使用 jar 文件运行 mvn cucumber 测试? - How to run mvn cucumber test using jar file? 无法在终端中运行mvn test - Unable to run mvn test in terminal Maven项目(Cucumber + TestNG + Selenium-Java)测试无法使用mvn clean install在命令行上运行测试 - Maven Project(Cucumber+TestNG+Selenium-Java] Test Can't Run test on command line with mvn clean install 如何将“mvn spring-boot:run”重命名为“mvn someName:run”? - How rename "mvn spring-boot:run" to "mvn someName:run"? 没有“测试运行:0,失败:0,错误:0,跳过:0”,即使 cucumber 测试是使用“mvn test”命令执行的 - no "Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, " even that cucumber test was executed using "mvn test" command 是否需要在 mvn spring-boot:run 之前进行 mvn 全新安装 - is it required to mvn clean install before mvn spring-boot:run 自动运行“ MVN验证” - Automatically run 'mvn verify' 我如何添加信息以在mvn和jenkins中运行时进行测试? - How I can add information to test when it run with mvn and in jenkins? 我怎样才能让Maven在“ MVN测试”中运行MySQL插件 - How can I get maven to run mySQL plug at “mvn test”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM