摘要:春季啓動黃瓜測試可以在「MVN測試」運行,但不是在「MVN驗證」
我正在用黃瓜克服彈簧啓動應用程序的一些測試。當我使用「mvn test」執行它們時,My Cucumber測試運行良好,但在「mvn verify」生命週期中執行它們時失敗。
詳情:
我的黃瓜亞軍類看起來是這樣的:
@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測試」,我可以在黃瓜亞軍被行家之前實例化的日誌中看到
Spring啓動插件實例化Spring Boot實例:
-------------------------------------------------------
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)
我知道我的黃瓜測試實際上是一個tegration試驗所以移動它爲「MVN驗證」生命週期階段的一部分來運行,而不是通過它重命名爲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 ---
我注意到,因爲我已經設置行家春季啓動插件預集成測試期間運行,黃瓜初始化之前執行它,但我不當然,如果這是錯誤。我確實嘗試配置spring-boot插件,以在「集成測試」期間啓動應用程序,而不是「預集成測試」,但似乎沒有太大的作用。
任何想法,我在做什麼錯在這裏?
我遇到了同樣的問題,我只是添加spring-boot-maven-plugin而沒有任何執行。 Java 9(181),Maven 3.5.0,Spring Boot 2.0.0.M5和Cucumber 1.2.5 – Tuno