TestNG - Custom reporter listener issue with failsafe plugin

Go To StackoverFlow.com

2

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.

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.

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>

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>

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

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

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

How to resolve this issue ?

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

2012-04-04 01:28
by appu


2

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.

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-04 17:50
by appu
I am getting the same issue, unresolved. https://stackoverflow.com/questions/48657869/running-maven-integration-test-inside-docker-container

Any help - Rohit Barnwal 2018-02-07 07:51