我用谷歌搜索了这个问题。我发现的结果表明我需要运行 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/