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

Allure @Step annotation does not work with groovy/spock code

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

勾选FAQ。我想你需要添加javaagent。 AspectJ用于处理步骤、附件和参数。

通过将 AspectJ 和 allure-junit-adaptor 添加到 pom.xml 中解决。现在 @Step 可以通过 spock 测试正确处理。

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