Cucumber-JVM 3-Maven的魅力2测试报告

时间:2018-08-27 10:12:26

标签: java maven cucumber cucumber-jvm allure

在这一点上,cucumber-jvm 3.x.x的最新发行版似乎没有可行的教程,只有较旧的1.x.xdocs)除外。

我不确定要使用哪个?

预期结果:

在运行target/target/site之后,使用Maven使用Cucumber-JVM 3在mvn testmvn verify中生成Allure2测试报告。

正在寻找工作中的pom.xml@CucumberOptions。谢谢!


更新:(2018-08-31)

pom.xml

<properties>
    <!-- Project -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <app.name>Simply Do - Balance Projector</app.name>
    <!-- Maven -->
    <timestamp>${maven.build.timestamp}</timestamp>
    <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format>
    <!-- Allure Test Report -->
    <aspectj.version>1.9.1</aspectj.version>
    <!-- Core Dependencies -->
    <selenium.version>3.14.0</selenium.version>
    <ngwebdriver.version>1.1.4</ngwebdriver.version>
    <cucumber.version>3.0.2</cucumber.version>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>${selenium.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.paulhammant/ngwebdriver -->
    <dependency>
        <groupId>com.paulhammant</groupId>
        <artifactId>ngwebdriver</artifactId>
        <version>${ngwebdriver.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.11.0</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.11.1</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-cucumber3-jvm -->
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-cucumber3-jvm</artifactId>
        <version>2.7.0</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>5.5.13</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.17</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.codoid.products/fillo -->
    <dependency>
        <groupId>com.codoid.products</groupId>
        <artifactId>fillo</artifactId>
        <version>1.18</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-site-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.7.1</version>
        </plugin>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-project-info-reports-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>3.0.0</version>
        </plugin>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jar-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <!-- Ignore src/main in JAR packaging -->
            <configuration>
                <classesDirectory>src</classesDirectory>
                <excludes>
                    <exclude>main</exclude>
                </excludes>
            </configuration>
        </plugin>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <includes>
                    <include>**/RunCukesTest.java</include>
                </includes>
                <testFailureIgnore>true</testFailureIgnore>
                <reportsDirectory>${project.build.directory}/test-output/${timestamp}</reportsDirectory>
                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                </argLine>
            </configuration>
            <dependencies>
                <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjweaver</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
        </plugin>
        <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-maven -->
        <plugin>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-maven</artifactId>
            <version>2.9</version>
            <configuration>
                <reportVersion>2.7.0</reportVersion>
                <allureDownloadUrl>https://github.com/allure-framework/allure2/releases/download/2.7.0/allure-2.7.0.zip</allureDownloadUrl>
            </configuration>
        </plugin>
        <!-- https://mvnrepository.com/artifact/net.masterthought/maven-cucumber-reporting -->
        <plugin>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>3.20.0</version>
            <executions>
                <execution>
                    <id>execution</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <projectName>${app.name}</projectName>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                        <jsonFiles>
                            <param>**/cucumber-report.json</param>
                        </jsonFiles>
                        <classificationFiles>
                            <param>**/classifications/*.properties</param>
                        </classificationFiles>
                        <parallelTesting>false</parallelTesting>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

构建日志:

pastebin

1 个答案:

答案 0 :(得分:4)

由于Cucumber API的重大更改,对于不同版本的Cucumber JVM,您将需要不同的Allure适配器:

  1. 黄瓜JVM 1.x需要allure-cucumber-jvm,格式化程序io.qameta.allure.cucumberjvm.AllureCucumberJvm
  2. 黄瓜JVM 2.x需要allure-cucumber2-jvm,格式化程序io.qameta.allure.cucumber2jvm.AllureCucumber2Jvm
  3. 黄瓜JVM 3.x需要allure-cucumber3-jvm,格式化程序io.qameta.allure.cucumber3jvm.AllureCucumber3Jvm
  4. 黄瓜JVM 4.x需要allure-cucumber4-jvm,格式化程序io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm

allure-maven插件负责生成报告,可以与上述任何适配器一起使用

更新: 我在这里用Cucumber JVM 3.x + Allure 2 + Maven创建了示例项目: https://github.com/letsrokk/stackoverflow-examples/tree/master/allure-cucumber-example

您可以运行测试并立即提供报告

$ mvn clean test allure:serve

或执行测试,而无需打开报告即可构建报告

$ mvn clean test allure:report
...
$ ls -l target/site/allure-maven-plugin/
total 4744
-rw-r--r--   1 user  CORP\Domain Users     2220 Aug 29 12:49 allure-maven.html
-rw-r--r--   1 user  CORP\Domain Users   726434 Aug 29 12:49 app.js
drwxr-xr-x  12 user  CORP\Domain Users      384 Aug 29 12:49 data
drwxr-xr-x   5 user  CORP\Domain Users      160 Aug 29 12:49 export
-rw-r--r--   1 user  CORP\Domain Users    15086 Aug 29 12:49 favicon.ico
drwxr-xr-x   7 user  CORP\Domain Users      224 Aug 29 12:49 history
-rw-r--r--   1 user  CORP\Domain Users      657 Aug 29 12:49 index.html
drwxr-xr-x   9 user  CORP\Domain Users      288 Aug 29 12:49 plugins
-rw-r--r--   1 user  CORP\Domain Users  1673197 Aug 29 12:49 styles.css
drwxr-xr-x  16 user  CORP\Domain Users      512 Aug 29 12:49 widgets