java - 无法使用 testng 和 maven 生成 allure 报告

标签 java maven testng pom.xml allure

TestNG版本

7.1.0

预期行为

mvn test 命令应该正常执行测试,知道相同的 POM 之前工作正常,直到我更新 testNG 和其他一些依赖项,我也在 testNG 和 maven 中使用 allure,现在如果我禁用 allure-TestNG 测试将被执行,但 allure 不会生成任何报告

实际行为

我收到此错误 各个测试结果请参阅 C:\Users\warrior\Desktop\MobileAutomationTest\target\surefire-reports。 请参阅转储文件(如果存在)[date].dump、[date]-jvmRun[N].dump 和 [date].dumpstream。 fork 的处理器 g/testng/IInvokedMethodListener2 中出现错误 org.apache.maven.surefire.booter.SurefireBooterForkException: fork 处理器中有错误g/testng/IInvokedMethodL 伊斯泰纳2

该问题可以在运行者身上重现吗?

  • [x] Maven
  • [x] IntelliJ

测试用例示例

POM文件

         <?xml version="1.0" encoding="UTF-8"?>
    <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>MobileAutomationTest</groupId>
    <artifactId>SafeApp</artifactId>
    <version>1.0-SNAPSHOT</version>


    <properties>
        <jre.level>1.8</jre.level>
        <jdk.level>1.8</jdk.level>
        <aspectj.version>1.9.5</aspectj.version>
    </properties>

    <build>
        <plugins>
            <!-- Compiler plug-in -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${jdk.level}</source>
                    <target>${jdk.level}</target>
                </configuration>
            </plugin>
            <!-- Added Surefire Plugin configuration to execute tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/java/TestNG.xml/</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.1.0</version>
        </dependency>
<!--        &lt;!&ndash; https://mvnrepository.com/artifact/io.qameta.allure/allure-testng &ndash;&gt;-->
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>2.13.0</version>
        </dependency>
        <!--https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server-->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.141.59</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
            <dependency>
                <groupId>io.appium</groupId>
                <artifactId>java-client</artifactId>
                <version>7.3.0</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/junit/junit -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13</version>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
            <dependency>
                <groupId>com.relevantcodes</groupId>
                <artifactId>extentreports</artifactId>
                <version>2.41.2</version>
            </dependency>
            <!-- log4j2 -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.7.29</version>
            </dependency>
        </dependencies>
        <reporting>
            <excludeDefaults>true</excludeDefaults>
            <plugins>
                <plugin>
                    <groupId>io.qameta.allure</groupId>
                    <artifactId>allure-maven</artifactId>
                    <version>2.10.0</version>
                    <configuration>
                        <reportDirectory>${basedir}\target\allure-report</reportDirectory>
                    </configuration>
                </plugin>
            </plugins>
        </reporting>

    </project>

最佳答案

这里的问题是 Allure 报告与 TestNG 7.1.0 不兼容。

TestNG 7.1.0 删除了监听器 IInvokedMethodListener2 接口(interface)。

这需要在 Allure 报告中修复。

我还在为此记录的 github 问题中添加了更多信息:https://github.com/cbeust/testng/issues/2246

关于java - 无法使用 testng 和 maven 生成 allure 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60249288/

相关文章:

java - 自动 JAX-RX 到 RAML

Java 与 SQL 映射器

java - 将大结果集转换为 json 的 mongodb java 驱动程序

apache - maven archetype 插件 - 在远程目录中找不到原型(prototype)。默认为内部目录

java - 编译时删除 JSP 文件中的前导空格/空格和空行

intellij-idea - 在 IntelliJ 中运行 TestNG 测试

java - TestNG 数据提供者优化

java - 使用编程 TestNG 运行 Spring 上下文测试

java - 在 java 中直接从 URL 将文件 POST 到 REST api,而不写入磁盘

java - Java 8 函数式编程中 'reduce' 函数的第三个参数的用途