我有这样的代码,以某种方式,当我通过Intellij运行时,它正在启动spring boot ConsumeServiceApplication
应用程序,但是当我通过maven运行时,它不是在启动相同的Spring Boot应用程序。
我缺少pom.xml中的任何内容吗?
import foo.ConsumeServiceApplication;
import com.intuit.karate.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.*;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = {
ConsumeServiceApplication.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = {AcceptanceTestConfiguration.class})
@ActiveProfiles("test")
public class AtddTest {
private static final String CUCUMBER_OUTPUT_DIR = "target/cucumber";
@Test
public void testMyService() throws Exception {
Results results = Runner.parallel(getClass(), 5, CUCUMBER_OUTPUT_DIR);
Assertions.assertEquals(0, results.getFailCount());
}
}
答案 0 :(得分:0)
我意识到public class MyListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
// This will be invoked as part of a warmup request, or
// the first user request if no warmup request was invoked.
}
public void contextDestroyed(ServletContextEvent event) {
// App Engine does not currently invoke this method.
}
}
都没有启动Spring引导应用程序,这是Maven Surefire插件的问题
详细信息位于
https://dzone.com/articles/why-your-junit-5-tests-are-not-running-under-maven
答案 1 :(得分:0)
要在此问题的答案中添加更多信息:
在使用spring-boot-maven-plugin
进行空手道测试之前,先使用mvn test
来连接Spring Boot服务器,这将足以达到目的。
您可以使用示例https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/test/ServerStart.java
,但在我看来,它要复杂得多。
对于使用空手道+弹簧启动的加特林性能测试,您将需要gatling-maven-plugin
,并结合mvn verify
和.scala文件顶部的以下代码段:
// Because Maven Failsafe will not start Spring-Boot before the Gatling test, we hard code it.
val app: ConfigurableApplicationContext = SpringApplication.run(classOf[MyApplication])
Runtime.getRuntime.addShutdownHook(new Thread() {
override def run(): Unit = app.stop()
})