TestNG - 故障安全插件的自定义报告监听器问题

标签 testng maven-failsafe-plugin

我有一个项目,其中使用 maven fail-safe 插件来运行集成测试。我正在使用 Maven + TestNG 框架组合。出于项目目的,之前我修改了 TestNG 的默认 XML 报告 以自定义项目需求。

我在一个 CustomReporter 类中实现了上述要求,该类扩展了 TestNG 的 IReporter 接口(interface)。之前我使用了surefire插件来运行这些测试方法,并在surefire插件中添加监听器机制按预期工作。

现在,为了某些项目需求,我需要迁移到故障安全插件。因此我通过配置 POM 文件绕过了 surefiretest 阶段执行。

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <skip>true</skip>
        </configuration>
</plugin>

然后我在 POM 文件中添加了故障安全配置,如下所示;

 <

plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.12</version>
    <executions>
        <execution>
            <id>fail-safe-myplug</id>
            <phase>integration-test</phase>
            <goals>
                <goal>integration-test</goal>
            </goals>
            <configuration>
                <skip>false</skip> 
                    <properties>                
                        <property>  
                        <name>listener</name>
                            <value>com.CustomXmlReport</value>
                                </property>
                            </properties>
                            <includes>
                                <include>**/*Test.java</include>
                            </includes>                     
                        </configuration>
                    </execution>
                </executions>

            </plugin>

使用这个新的 POM,使用 failsafe 插件进行集成测试调用失败。以下是日志;

Running com.myPack.AppTest
Configuring TestNG with: org.apache.maven.`surefire`.testng.conf.TestNGMapConfigurator@ab50cd
org.apache.maven.surefire.util.`SurefireReflectionException: java.lang.reflect.InvocationTargetException`; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
Caused by: java.lang.IncompatibleClassChangeError: Expected static method org.testng.reporters.XMLReporterConfig.getTimestampFormat()Ljava/lang/String;
    at com.myPack.CustomSuiteResultWriter.getTestResultAttributes(CustomSuiteResultWriter.java:175)
    at com.myPack.CustomSuiteResultWriter.addTestResult(CustomSuiteResultWriter.java:138)
    at com.myPack.CustomSuiteResultWriter.addTestResults(CustomSuiteResultWriter.java:117)
    at com.myPack.CustomSuiteResultWriter.writeAllToBuffer(CustomSuiteResultWriter.java:76)
    at com.myPack.CustomSuiteResultWriter.writeSuiteResult(CustomSuiteResultWriter.java:56)
    at com.myPack.CustomXmlReportGenerator.writeSuiteToBuffer(CustomXmlReportGenerator.java:102)
    at com.myPack.CustomXmlReportGenerator.writeSuite(CustomXmlReportGenerator.java:65)
    at com.myPack.CustomXmlReportGenerator.generateReport(CustomXmlReportGenerator.java:42)
    at org.testng.TestNG.generateReports(TestNG.java:780)
    at org.testng.TestNG.run(TestNG.java:766)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:76)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:112)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:115)
    ... 9 more

尽管我在集成测试阶段使用failsafe插件,但我收到了异常

使用 org.apache.maven.surefire.testng.conf.TestNGMapConfigurator@ab50cd 配置 TestNG org.apache.maven.surefire.util.`SurefireReflectionException

如何解决这个问题?

注意:当我尝试使用 surefire 插件执行测试时,监听器机制按预期工作。

最佳答案

实际上问题是与FailsafeTestNG版本的兼容性。我使用的是 TestNG 5.9vfailsafe 插件 2.12v。这是问题的根本原因。

我将 Failsafe 版本降级到 2.5v,问题得到了解决。

感谢 google groups 引导我从版本角度思考。 http://groups.google.com/group/testng-users/browse_thread/thread/b54417e5a61c5c62

关于TestNG - 故障安全插件的自定义报告监听器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10003812/

相关文章:

java - 当我的测试失败或发生异常时,我需要始终注销我的应用程序。我应该怎么做?

maven - 如果设置了skipITs,如何跳过maven阶段预集成测试?

java - 配置 maven-failsafe-plugin 以查找不在 src/test/java 中的集成测试

maven - 是否必须指定 maven-failsafe-plugin 才能运行集成测试?

java - 使用数据提供者时使用 Test-ng 优先级

java - 配置失败: Method beforeTest requires 1 parameters but 0 were supplied in the @Configuration annotation

maven - 故障安全插件不会在一个项目上运行,但会在另一个项目上运行——为什么?

java - Maven 在集成测试阶段运行 jetty

java - 无法使用 ChromeDriver 在 Eclipse 中运行 TestNG 测试用例

java - 无法从 TestNG Class ->java.lang.NullPointerException 调用两个单独类的属性