我为我的 Spring Boot 应用程序编写了骆驼测试用例,如下所示。
@RunWith(CamelSpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
@ContextConfiguration(classes = Application.class)
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
@UseAdviceWith
public class CamelTestClass {
@Autowired
private CamelContext camelContext;
private String routeID = "routeId";
Logger log = Logger.getLogger(String.valueOf(CamelSpringBootApplication.class));
@Test
@DirtiesContext
public void test1() throws Exception {
ModelCamelContext mcc = camelContext.adapt(ModelCamelContext.class);
RouteReifier.adviceWith(mcc.getRouteDefinition(routeID), mcc, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
doSOmething
}
});
mcc.start();
assertion
mcc.stop();
}
@Test
@DirtiesContext
public void test2() throws Exception {
ModelCamelContext mcc = camelContext.adapt(ModelCamelContext.class);
RouteReifier.adviceWith(mcc.getRouteDefinition(routeID), mcc, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
doSomething
}
});
mcc.start();
assertion
mcc.stop();
}
@Test
@DirtiesContext
public void test3() throws Exception {
ModelCamelContext mcc = camelContext.adapt(ModelCamelContext.class);
RouteReifier.adviceWith(mcc.getRouteDefinition(routeID), mcc, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
doSomething
}
});
mcc.start();
assertion
mcc.stop();
}
}
所以编写了 3 个测试用例,在测试用例的每个开头我都必须启动骆驼上下文并在最后清除它。使用此设置,在 Maven 构建测试测试中需要很长时间才能完成。大约有 30 个测试用例,构建需要 25 分钟才能完成。在运行时间方面是否有优化测试用例的空间?