我尝试从 JUnit 套件类启动我的 Spring Boot 应用程序,但应用程序未启动。我的套件类调用两个测试类,每个测试类对 Spring Boot 应用程序进行 API 调用
这两个测试类都会在根 POM 上使用
mvn clean install
通过,但在从 SuiteRunner 类调用时,在 same 执行中会失败。
套房课程
import com.intuit.karate.KarateOptions;
import com.intuit.karate.junit4.Karate;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Karate.class)
@Suite.SuiteClasses({
BasicParallelKarateTest.class,
DynamicParallelKarateTest.class
})
@KarateOptions(tags = "~@ignore")
public class JUnitSuiteTest { }
构建 -
mvn clean install
堆栈跟踪
[ERROR] Errors:
[ERROR] BattleTest.feature:11 -
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
...
...
...
[ERROR] ResultTest.feature:10 -
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
[ERROR] Tests run: 13, Failures: 0, Errors: 13, Skipped: 0
部分解决方案 - 不在 CI 中运行套件类
@KarateOptions(tags = "~@ignore")
@RunWith(JUnitPlatform.class)
@SelectClasses({
BasicParallelKarateTest.class,
DynamicParallelKarateTest.class
})
@IncludeEngines({"junit-jupiter","junit-vintage"})
public class JUnitSuiteTest {}
在测试中添加 SpringClassRule 和 SpringMethodRule
public class MyTest {
@ClassRule
public static final SpringClassRule springClassRule = new SpringClassRule();
@Rule
public final SpringMethodRule springMethodRule = new SpringMethodRule();
另一种选择是使用 @RunWith(SpringRunner.class) 运行测试套件,但该套件不能有两个测试运行程序,因此您必须删除 @RunWith(Karate.class)。我想这不是一个选择,对吧?