Allure @Step注释不适用于groovy / spock代码

时间:2016-11-03 17:12:18

标签: groovy spock allure

我正在使用spock框架和groovy进行测试。我也使用allure-spock-1.0-adapter生成Allure报告。报告看起来很好,但没有显示结果中的步骤。所有groovy方法都使用@Step注释,但仍未记录在报告中。 如何解决?

2 个答案:

答案 0 :(得分:0)

检查FAQ。我想你需要添加javaagent。 AspectJ用于处理步骤,附件和参数。

答案 1 :(得分:0)

通过在pom.xml中添加AspectJ和allure-junit-adapter解决了这个问题。现在使用spock测试正确处理@Step。

请参阅pom.xml示例:

<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>allure.spock.demo</groupId>
<artifactId>allure-spock</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
    <allure.version>1.4.23.HOTFIX1</allure.version>
    <aspectj.version>1.8.9</aspectj.version>
    <compiler.version>1.7</compiler.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                </argLine>
                <includes>
                    <include>**/*Spec.*</include>
                </includes>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjweaver</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>1.1-groovy-2.4-rc-3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-junit-adaptor</artifactId>
        <version>${allure.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.4.6</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-spock-1.0-adaptor</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

<reporting>
    <excludeDefaults>true</excludeDefaults>
    <plugins>
        <plugin>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-maven-plugin</artifactId>
        </plugin>
    </plugins>
</reporting>