2

我有一个项目,我在其中使用 mavenfail-safe插件来运行集成测试。我正在使用Maven + TestNG框架组合。为了项目的目的,之前我已经修改了TestNG的默认XML报告来定制项目的需要。

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

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

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

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

如何解决这个问题?

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

4

1 回答 1

2

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

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

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

于 2012-04-04T17:50:12.967 回答