我有一个项目,我在其中使用 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
插件执行测试时,侦听器机制按预期工作。