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

时间:2012-04-04 01:28:39

标签: testng maven-failsafe-plugin

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

我在 CustomReporter 类中实现了上述要求,该类扩展了TestNG的IReporter接口。之前我使用surefire插件来运行这些测试方法,并在surefire插件中添加listener mechanism按预期工作。

现在针对某些项目需求,我需要迁移到failsafe插件。所以我通过配置POM文件来绕过test surefire阶段执行。

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

然后我在POM文件中添加了failafe配置,如下所示;

 <

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阶段使用integration-test插件,但我得到了异常

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

如何解决此问题?

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

1 个答案:

答案 0 :(得分:2)

实际上问题是,与FailsafeTestNG版本的兼容性。我在TestNG 5.9v使用了failsafe plugin 2.12v。这是该问题的根本原因。

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

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