Я создаю отдельный jar-файл, интегрирующий следующие библиотеки:
Код: Выделить всё
jakarta.inject
jakarta.inject-api
io.cucumber
cucumber-java
io.cucumber
cucumber-spring
org.springframework
spring-core
org.springframework
spring-context
org.springframework
spring-test
junit
junit
Код: Выделить всё
import io.cucumber.java.en.Given;
import io.cucumber.spring.CucumberContextConfiguration;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@CucumberContextConfiguration
@ContextConfiguration("classpath:spring.main.xml")
public class MyStepDefinitions {
private static final Logger LOGGER = LoggerFactory.getLogger(Dhis2StepDefinitions.class);
@Inject
@Named("testAtomicInt")
@Autowired
private AtomicInteger testCounter;
@Given("I have {int} cukes in my belly")
public void i_have_n_cukes_in_my_belly(int cukes) {
testCounter.addAndGet(cukes);
LOGGER.info("TEST: ", cukes, testCounter, this);
}
}
Мой "spring.main.xml" для no содержит только один bean-компонент:
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/78548216/cucumber-spring-not-injecting-bean[/url]
Мобильная версия