Run cucumber tests from spring boot CommandLineRunner

时间:2019-05-22 18:38:04

标签: java spring spring-boot cucumber cucumber-jvm

I am trying to run cucumber tests from a spring boot cli application. My project structure is as follows:

app.jar - spring boot fat jar

util-autoconfig.jar - autoconfiguration class which loads 1 bean, Foo.class

test1.jar - contains step defs and some classes annotated with @Component

test2.jar - like test1.jar, just different steps and different classes

I invoke the application like so:

java -jar -Dloader.path=$LIB/test1.jar app.jar

I use a common base package name so my test{1,2}.jar will be scanned during start up.

Internally, app.jar has a CommandLineRunner which executes and configures a cucumber runtime via cucumber.runtime.Runtime.

This all works. My features are executed and I see output to the console for success/failure. However, I am not using any spring injection in my step defs.

I want to @Autowired the Foo bean from util-autoconfig into the step defs in each test jar. This is not working.

I have cucumber-spring on the classpath, I already unpacked cucumber-java when my fat jar is created. Again, I can run cucumber just fine.

I just cannot inject beans from the spring boot application context into my step defs. I suspect it would work fine if I use cucumber.xml, but I don't want to use it nor do I want to then have two contexts initialized (via spring boot then via cucumber's SpringFactory).

Is this possible? This would allow me to externalize a lot of stuff and just switch steps via the loader.path property which is my primary need.

0 个答案:

没有答案