简体   繁体   中英

Invoking cucumber from Spring boot

I am trying to invoke cucumber from a Spring boot app. I have all the dependencies in my gradle build file. compile("info.cukes:cucumber-java8:1.2.5") compile("info.cukes:cucumber-junit:1.2.5") compile("info.cukes:cucumber-spring:1.2.5") And on examing my app's spring boot jar, I see the cucumber jars.

In the main class I have

        String[] cucumberOptions = new String[]{"--glue","mypackage.steps","--plugin", "pretty",
                "--plugin", "html:target/cucumber-html-report","--plugin", "json:target/cucumber.json",
                "--plugin", "junit:target_junit/cucumber.xml",
                "classpath:mypackage.features"
               };

 cucumber.api.cli.Main.main(cucumberOptions );

On executing my jar, I get the error - No backends were found. Please make sure you have a backend module on your CLASSPATH.

I also have a runner class and corresponding step classes. I have my step classes with the following annotation-

@ContextConfiguration(
        loader = SpringApplicationContextLoader.class,
        classes={Application.class})
@RunWith(SpringJUnit4ClassRunner.class)
public class MySteps{
....
}
My runner class is below.

@RunWith(Cucumber.class)
public class MyRunner{

}

Question - is how do I invoke cucumber from my Spring boot app?

i got this to work by updating my spring boot gradle script to use a fat jar boot repackage option. Still curious as to why the spring boot integrated jar does not work though.

I got this to work by instructing spring=boot-maven-plugin to unpack the cucumber-java jar

<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <requiresUnpack>
                <dependency>
                    <groupId>info.cukes</groupId>
                    <artifactId>cucumber-java</artifactId>
                </dependency>
            </requiresUnpack>
        </configuration>
    </plugin>
</plugins>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM