java - 在 eclipse 中作为 TestNG Suite 运行项目时如何生成 Allure xml?

标签 java maven testng allure

我用谷歌搜索了这个问题。我发现的结果表明我需要运行 maven/ant 构建来生成 xml。

我的项目是 Maven 和 TestNG 项目。但在调试时,我们在 eclipse 中使用“Run as TestNG Suite”选项。

我已将以下代码添加到我的 testng.xml 中。

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

这会在project\target\site\allure-maven-plugin\data目录中生成UUID-testsuite.xml,但报告只包含套件标题,没有显示其他数据。

我知道为了使@Step和@Attachment注释工作,我们需要在配置中正确启用AspectJ。我不确定如何在 testng.xml 文件中执行此操作。

如果我在这里遗漏了什么,请告诉我。

最佳答案

假设您在测试代码中定义了@Step和@Attachment方法,则只需在pom.xml文件中添加aspectjweaver依赖项即可。请引用这个Allure github wiki page

<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 将使用 listener 调用 testng

<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

也可以引用这个example project为了更清楚。

关于java - 在 eclipse 中作为 TestNG Suite 运行项目时如何生成 Allure xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30400272/

相关文章:

testng - 将Selenium,TestNG和ReportNG与Gradle结合使用

java - Java 加密扩展的 key 长度限制

java - Java中接口(interface)和列表的返回类型和参数?

java - Tesseract:在 Linux 远程主机中构建源代码的替代方案?

java - Maven - 无法在多模块项目中激活配置文件

maven - pom.xml 和 Apache Maven 中的有效 pom 有什么区别?

java - 正则表达式 + Java - 如何捕获尾随数字和其他所有内容

java - 当我想添加更多数据时如何不覆盖文本文件中已有的数据

java - 如何通过JAVA Reflection处理一个注解的所有特征

java - java中testng注解的使用方法