2012-04-04 90 views
1

我有一個使用maven fail-safe插件運行集成測試的項目。我正在使用Maven + TestNG框架組合。出於項目目的,我早先修改了TestNG的默認XML報告以定製項目需求。TestNG - 使用故障安全插件的自定義記者監聽器問題

我在CustomReporter類中實現了上述要求,它擴展了TestNG的IReporter接口。之前我使用surefire插件來運行這些測試方法,並在surefire插件中添加listener mechanism按預期工作。

現在對於某些項目需求,我需要遷移到故障安全插件。所以我通過配置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`[email protected] 
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 

Eventhough我在integration-test階段使用failsafe插件,我得到異常

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

如何解決這個問題?

注意:當我試圖使用surefire插件執行測試時,聽衆mechanishm按預期工作。

回答

1

其實問題是,與FailsafeTestNG版本的兼容性。我正在使用TestNG 5.9vfailsafe plugin 2.12v。這是問題的根源。

我將Failsafe版本降級爲2.5v,問題得到解決。

感謝谷歌小組引導我在版本角度思考。 http://groups.google.com/group/testng-users/browse_thread/thread/b54417e5a61c5c62

+0

我遇到同樣的問題,未解決。 https://stackoverflow.com/questions/48657869/running-maven-integration-test-inside-docker-container 任何幫助? – 2018-02-07 07:51:32