Re: [testng-users] Re: Cannot load listeners when using testNG through Maven/surefire

6,209 views
Skip to first unread message

Cédric Beust ♔

unread,
May 17, 2013, 10:04:28 AM5/17/13
to testng...@googlegroups.com
This is fixed in TestNG 6.8.5 (note that I haven't updated the Eclipse plug-in yet).

-- 
Cedric


-- 
Cédric



On Fri, May 17, 2013 at 1:37 AM, <hop...@gmail.com> wrote:
Hi, all!
 
I faced the same problem using maven failsafe plugin. I execute 'maven integration-test' in Eclipse. If I add listener in suite xml file (like testng.xml) then it works, but if I specify Listener in pom (using <property>), I get:
 
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] There was an error in the forked process
org.testng.TestNGException:
Cannot load class from file: class com.mvsc.dmvdesk.test.SuiteLoggingTracer
 at org.testng.internal.ClassHelper.fileToClass(ClassHelper.java:522)
 at org.testng.TestNG.configure(TestNG.java:1452)
 at org.testng.TestNG.configure(TestNG.java:1620)
 at org.apache.maven.surefire.testng.conf.TestNGMapConfigurator.configure(TestNGMapConfigurator.java:52)
 at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:175)
 at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
.....
 
I use TestNG 6.8.1, Maven 2.2.1 and Eclipse Helios Service Release 2.
 
Thank you.

вторник, 16 апреля 2013 г., 11:49:34 UTC+4 пользователь romanosmat написал:
Greetings!

We are trying to integrate our testNG environment with maven and the surefire plugin and we are facing a problem when trying to use private listeners.

Here is a part of the pom.xml:
<plugins>
 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.14.1</version>
        <configuration>
         <properties>
            <property>
              <name>usedefaultlisteners</name>
              <value>false</value> 
            </property>
            <property>
              <name>listener</name>
              <value>listeners.MyRetryListener,listeners.MySuiteListener,org.testng.reporters.XMLReporter,org.uncommons.reportng.HTMLReporter</value>
            </property>
          </properties>
          <suiteXmlFiles>
            <suiteXmlFile>src/com/sen/suites/login/MyXML.xml</suiteXmlFile>
               </suiteXmlFiles>
    </configuration>
  </plugin>
  </plugins>

Trying to run surefire:test target will result in the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test (default-cli) on project suites: Execution default-cli of goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test failed: There was an error in the forked process
[ERROR] org.testng.TestNGException:
[ERROR] Cannot load class from file: class listeners.MyRetryListener
[ERROR] at org.testng.internal.ClassHelper.fileToClass(ClassHelper.java:522)
[ERROR] at org.testng.TestNG.configure(TestNG.java:1452)
[ERROR] at org.testng.TestNG.configure(TestNG.java:1620)
[ERROR] at org.apache.maven.surefire.testng.conf.TestNGMapConfigurator.configure(TestNGMapConfigurator.java:52)
[ERROR] at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:175)
[ERROR] at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
[ERROR] at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:96)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[ERROR] at java.lang.reflect.Method.invoke(Unknown Source)
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
[ERROR] at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:159)
[ERROR] at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:87)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)

The listeners we are trying to use are in a jar file that is already added in the classpath (no dependency errors seem to exist). This setup works without maven integration (like running the same config through command line). It is also successful when the listeners are removed.
 
Has anybody any idea on how to overcome this? Has anybody else encountered similar problems? Perhaps it is more like a surefire error but I would be grateful if I had a second opinion.

Thank you in advance!
R.M.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

S. NiGhMa

unread,
Sep 11, 2013, 11:49:16 AM9/11/13
to testng...@googlegroups.com
I get the same type of error when I try to use ReportNG. Could you help me?

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>eu.europa.ec.estat</groupId>
    <artifactId>essmh-selenium-tests</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>essmh-selenium-tests</name>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.35.0</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.2</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.testng</groupId>
                    <artifactId>testng</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.5</version>

                <configuration>
                    <properties>
                        <property>
                            <name>usedefaultlisteners</name>
                            <value>false</value>
                        </property>
                        <property>
                            <name>listener</name>
                            <value>org.uncommons.reportng.HTMLReporter,
                                org.uncommons.reportng.JUnitXMLReporter</value>
                        </property>
                    </properties>
                    <workingDirectory>target/</workingDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Logs:

[INFO] Scanning for projects...
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building essmh-selenium-tests 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ essmh-selenium-tests ---
[INFO] Deleting C:\Users\estat-B3transmission\dev\Selenium\tests\target
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ essmh-selenium-tests ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\estat-B3transmission\dev\Selenium\tests\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ essmh-selenium-tests ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ essmh-selenium-tests ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\estat-B3transmission\dev\Selenium\tests\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ essmh-selenium-tests ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\estat-B3transmission\dev\Selenium\tests\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ essmh-selenium-tests ---
[INFO] Surefire report directory: C:\Users\estat-B3transmission\dev\Selenium\tests\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
org.apache.maven.surefire.booter.SurefireExecutionException: Cannot find listener class
                                org.uncommons.reportng.JUnitXMLReporter; nested exception is java.lang.ClassNotFoundException:
                                org.uncommons.reportng.JUnitXMLReporter; nested exception is org.apache.maven.surefire.testset.TestSetFailedException: Cannot find listener class
                                org.uncommons.reportng.JUnitXMLReporter; nested exception is java.lang.ClassNotFoundException:
                                org.uncommons.reportng.JUnitXMLReporter
org.apache.maven.surefire.testset.TestSetFailedException: Cannot find listener class
                                org.uncommons.reportng.JUnitXMLReporter; nested exception is java.lang.ClassNotFoundException:
                                org.uncommons.reportng.JUnitXMLReporter
java.lang.ClassNotFoundException:
                                org.uncommons.reportng.JUnitXMLReporter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:103)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at org.apache.maven.surefire.testng.conf.AbstractDirectConfigurator.loadClass(AbstractDirectConfigurator.java:103)
    at org.apache.maven.surefire.testng.conf.AbstractDirectConfigurator.loadListenerClasses(AbstractDirectConfigurator.java:91)
    at org.apache.maven.surefire.testng.conf.TestNGMapConfigurator.configure(TestNGMapConfigurator.java:62)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:59)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:141)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.579s
[INFO] Finished at: Wed Sep 11 17:46:50 CEST 2013
[INFO] Final Memory: 12M/28M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test (default-test) on project essmh-selenium-tests: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\estat-B3transmission\dev\Selenium\tests\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Kirill Kozlov

unread,
Feb 17, 2014, 3:37:13 AM2/17/14
to testng...@googlegroups.com
I know, that It's an old issue, but I faced the same problem recently. I mean the same as in the previous message. I hope my message would be helpful for someone else searching the answer via google.
The problem is not in TestNG, but in maven-surefire-plugin. And It's the other problem than described in the first message of the topic.
The solution is to put all your listeners at the same line in pom.xml. You should use comma as a separator, no any line breaks.
It's the implementation of maven-surefire-plugin. It parses the value of the property with the following code: String[] classNames = listenerClasses.split( " *, *" );
So, fix your pom.xml like that:
<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>

Kangs

unread,
Apr 16, 2015, 10:00:31 PM4/16/15
to testng...@googlegroups.com
To add to Kirill's information, if you have the habit of auto formatting using Eclipse Ctrl+Shift+F (or  Shift+Command+F), go to Eclipse --> Preferences --> XML --> XML Files --> Editor --> Line Width --> Change the default value 72 to higher value like 160.
This will prevent the comma separated value to be automatically indented to the next line.
Screenshot 2015-04-16 18.50.03.png
Reply all
Reply to author
Forward
0 new messages