У меня возникли некоторые проблемы с использованием пружинно-кассандрового блока, пружинного башмака и пружинного огурца. Приведенная ниже конфигурация отлично работает для модульных тестов, но как только я добавляю spring-cucumber в микс и пытаюсь выполнить некоторые интеграционные тесты, оказывается, что он полностью игнорирует мой MyCustomOrderedTestExecutionListener и загружает пружинную загрузку перед cassandra, давая мне «NoHostFoundException».
Я действительно мог бы воспользоваться советом о том, как обеспечить загрузку встроенной кассандры. Любая помощь с благодарностью.
Следующая настройка:
@ActiveProfile("INTEGRATION_TEST")
@SpringBootTest
@EmbeddedCassandra(configuration = "cassandra.yaml")
@TestExecutionListeners(
listeners = MyCustomOrderedTestExecutionListener.class,
mergeMode = MERGE_WITH_DEFAULTS)
@CassandraDataSet(value = "cql/dataset1.cql", keyspace = "mykeyspace")
public class TestStepDef{
//omitted for brevity
}
My Custom заказал слушателя выполнения теста:
public class MyCustomOrderedTestExecutionListener extends AbstractTestExecutionListener {
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
//omitted for brevity
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}
Тестер огурцов:
@RunWith(Cucumber.class)
@CucumberOptions(features="resources/features", glue="resources/glue")
public class TestRunner {}
Edit:
Глядя на пружинную фабрику огуречной пружины, контекст приложения загружается еще до того, как будет выполнен класс передTestClass (beforeTestClass выполняется notifyContextManagerAboutTestClassStarted):
public void start() {
if (this.stepClassWithSpringContext != null) {
this.testContextManager = new CucumberTestContextManager(this.stepClassWithSpringContext);
} else if (this.beanFactory == null) {
this.beanFactory = this.createFallbackContext();
}
this.notifyContextManagerAboutTestClassStarted();
if (this.beanFactory == null || this.isNewContextCreated()) {
this.beanFactory = this.testContextManager.getBeanFactory();
Iterator var1 = this.stepClasses.iterator();
while(var1.hasNext()) {
Class<?> stepClass = (Class)var1.next();
this.registerStepClassBeanDefinition(this.beanFactory, stepClass);
}
}
GlueCodeContext.INSTANCE.start();
}
Пройдя глубже, мы видим, что контекст приложения загружен здесь:
class CucumberTestContextManager extends TestContextManager {
public CucumberTestContextManager(Class<?> testClass) {
super(testClass);
this.registerGlueCodeScope(this.getContext());
}
private ConfigurableApplicationContext getContext() {
return (ConfigurableApplicationContext)this.getTestContext().getApplicationContext();
}
...
}
Какой-нибудь совет, как это обойти?