2

I googled about this question. The results I found suggested that I need to run a maven/ant build to generate the xml.

My project is an Maven & TestNG project. But while debugging we use the option 'Run as TestNG Suite' in eclipse.

I have added the following code to my testng.xml.

<listeners>
    <listener class-name="ru.yandex.qatools.allure.testng.AllureTestListener" />
</listeners>

This generates the UUID-testsuite.xml in project\target\site\allure-maven-plugin\data directory, but the report just contains the suite title and no other data is displayed.

I understand that in order to make @Step and @Attachment annotations work we need to correctly enable AspectJ in configuration. I am not sure how to do this in testng.xml file.

Please let me know, if I am missing something here.

4

1 回答 1

2

假设您在测试代码中定义了 @Step 和 @Attachment 方法,您只需在 pom.xml 文件中添加 aspectjweaver 依赖项。参考这个 Allure github wiki 页面

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.14</version>
            <configuration>
                <testFailureIgnore>false</testFailureIgnore>
                <argLine>
                    -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                </argLine>
                <!--only for 1.3.* TestNG adapters. Since 1.4.0.RC4, the listener adds via ServiceLoader-->
                <properties>
                    <property>
                        <name>listener</name>
                        <value>ru.yandex.qatools.allure.testng.AllureTestListener</value>
                    </property>
                </properties>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjweaver</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

maven-surefire-plugin 将调用 testnglistener

<properties>
   <property>
      <name>listener</name>
      <value>ru.yandex.qatools.allure.testng.AllureTestListener</value>
   </property>
</properties>

并将 aspectj 设置作为 jvm 参数传递:

- javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar

您也可以参考这个示例项目以获得更清晰的信息。

于 2016-01-13T17:59:45.810 回答