简体   繁体   English

黄瓜和Spring启动集成有错误

[英]Cucumber and Spring boot integration has error

Spring boot and cucumber integration, when I do package this project become jar use mvn package command and produce advvic-1.0.jar. Spring启动和黄瓜集成,当我打包这个项目成为jar使用mvn package命令并生成advvic-1.0.jar。 But, if I run this jar 但是,如果我运行这个罐子

java -jar target/advvic-1.0.jar

I get this error : 我收到此错误:

Caused by: cucumber.runtime.CucumberException: No backends were found. 引起:cucumber.runtime.CucumberException:没有找到后端。 Please make sure you have a backend module on your CLASSPATH. 请确保您的CLASSPATH上有后端模块。

However, if I extract this jar, I found cucumber-java.jar on lib folder 但是,如果我提取这个jar,我在lib文件夹中找到了cucumber-java.jar

this my pom : 这是我的pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.advvic.cucumber.spring</groupId>
    <artifactId>advvic</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>cucumber-spring-boot</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>

        <spring-boot.version>1.4.1.RELEASE</spring-boot.version>

        <cucumber.version>1.2.5</cucumber.version>
        <selenium.version>3.0.1</selenium.version>
        <htmlunit.version>2.13</htmlunit.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jdbc</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>20.0</version>
        </dependency>

        <!--Selenium server dependency is for version 3 and up -->
        <!--https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>${selenium.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>

        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>

        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.20.0-GA</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <executions>
                    <execution>
                        <configuration>
                            <executable>true</executable>
                            <attach>true</attach>
                        </configuration>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <executable>true</executable>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

I had the exact same problem with a Spring Boot application that I wanted to use as a runner for Cucumber tests. 我有一个Spring Boot应用程序的完全相同的问题,我想用它作为Cucumber测试的跑步者。

The problem is that Spring Boot repackages everything in its own way, thus making it hard for the default Cucumber ResourceLoaders to locate any cucumber.runtime.Backend classes as well as feature files and step definitions. 问题是Spring Boot以自己的方式重新打包所有内容,因此默认的Cucumber ResourceLoaders很难找到任何cucumber.runtime.Backend类以及特征文件和步骤定义。

What I ended up doing was to implement a custom cucumber.runtime.io.ResourceLoader using Spring specific classes to search the classpath. 我最终做的是使用Spring特定的类来实现自定义的cucumber.runtime.io.ResourceLoader来搜索类路径。 I got the idea for that at https://stackoverflow.com/a/17283721/3216618 我在https://stackoverflow.com/a/17283721/3216618上得到了这个想法

PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
String locationPattern = ... use path and suffix to 
Resource[] resources = resolver.getResources(locationPattern);

Finally you need to create an Iterable from the found org.springframework.core.io.Resource[] 最后,你需要从找到的org.springframework.core.io.Resource []创建一个Iterable。

Maybe this can help you: 也许这可以帮助你:

       <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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