Working off of this post: Cucumber: no backend found when running from Spring Boot jar
I am attempting to get Cucumber to work full within a live Spring Boot app. I currently have a POC app using the aforementioned post's code to create a Cucumber Runtime and it runs a simple Feature/Steps class with a Bean referenced:
Service:
public void testFeature(){
RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList<String>(asList("--glue", "org.bdd.poc", "--no-dry-run", "--monochrome", "classpath:features")));
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
ResourceLoader resourceLoader = new CustomMultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
try {
runtime.run();
} catch (IOException e) {
e.printStackTrace();
}
}
DemoSteps:
(no class annotation)
public class DemoSteps {
@Autowired
private MyBean bean;
public DemoSteps(){
System.err.println("STEP INIT");
}
@Given("a proof of concept")
public void givenAPOC(){
}
@When("doing a demo")
public void whenDemo(){
}
@Then("it should talk to a bean")
public void thenItShouldTalkToABean(){
this.bean.poke();
}
}
Bean:
@Component
public class MyBean {
public void poke(){
System.err.println("I'VE BEEN POKED! THE PAIN!");
}
}
The DemoSteps.java class has this as a class field with @Autowired in place, but while it is neither populating the bean reference or failing after DemoSteps construction. I see through debugging that there are spring bean factories being used to create the Steps instance, but nothing regarding autowiring is being touched. I am guessing in order to apply some connection to the main SpringContext lies in either:
- An appropriate Backend implementation
- An appropriate Glue implementation
I know that something similar was able to be accomplished using the Karate framework, but I have not found what is allowing that to make the connection.
Currently using Spring Boot 2.3.0 and Cucumber 2.4.0, unpacked per the "spring-boot-maven-plugin" config.