TestNG - 带有故障安全插件的自定义报告器侦听器问题 [英] TestNG - Custom reporter listener issue with failsafe plugin

查看:35
本文介绍了TestNG - 带有故障安全插件的自定义报告器侦听器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a project in which I used maven fail-safe plugin to run the integration tests. I am using the Maven + TestNG framework combination. For the project purpose, earlier I have modified the TestNG's default XML Report to customize the project needs.

我在扩展 TestNG 的 IReporter 接口的 CustomReporter 类中实现了上述要求.之前我使用了surefire插件来运行这些测试方法,并且在surefire插件中添加了listener机制可以正常工作.

I implemented the above said requirement in a CustomReporter class which extends the TestNG's IReporterinterface. Earlier I used surefire plugin to run these test methods and adding the listener mechanism in the surefire plugin works as expected.

现在对于某些项目需求,我需要迁移到故障安全插件.所以我通过配置POM文件绕过了surefiretest阶段执行

Now for certain project needs, I need to migrate to failsafe plugin. So I bypassed the test phase execution of surefire by configuring the POM file.

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

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

Then I have added the failsafe configuration in the POM file as below;

 <

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 插件的集成测试调用失败.以下是日志;

With this new POM, integration test invocation with failsafe plugin is failing. Following are the log;

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

即使我在 integration-test 阶段使用了 failsafe 插件,我也遇到了异常

Eventhough I am using failsafe plugin in the integration-test phase, I am getting the exception

使用以下命令配置 TestNG:org.apache.maven.surefire.testng.conf.TestNGMapConfigurator@ab50cdorg.apache.maven.surefire.util.`SurefireReflectionException

Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNGMapConfigurator@ab50cd org.apache.maven.surefire.util.`SurefireReflectionException

如何解决这个问题?

注意:当我尝试使用 surefire 插件执行测试时,listener mechanishm 按预期工作.

Note : When I tried to execute the tests using surefire plugin, the listener mechanishm works as expected.

推荐答案

其实问题在于与 FailsafeTestNG 版本的兼容性.我使用 TestNG 5.9vfailsafe plugin 2.12v.这是问题的根本原因.

Actually the issue is, the compatibility with Failsafe and TestNG versions. I was using TestNG 5.9v with failsafe plugin 2.12v. This is the root cause for the issue.

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

I downgraded the Failsafe version to 2.5v and the issue got resolved.

感谢谷歌小组指导我从版本角度思考.http://groups.google.com/group/testng-users/browse_thread/thread/b54417e5a61c5c62

Thanks to google groups for guiding me to think in version perspective. http://groups.google.com/group/testng-users/browse_thread/thread/b54417e5a61c5c62

这篇关于TestNG - 带有故障安全插件的自定义报告器侦听器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆