Re: [testng-users] Maven + TestNG runs fine on Eclipse with TestNG/Maven plugins, but fail to work when calling it from command-line

3,055 views
Skip to first unread message

Krishnan Mahadevan

unread,
Jun 12, 2012, 10:16:30 PM6/12/12
to testng...@googlegroups.com
Is
      <class name="com.something.STest.UserTest" />
located in src/test/java or src/main/java ?

On Wednesday, June 13, 2012, Sam X wrote:

Hello all,

It's my first time come to here and ask question, but this is a very tricky one which I cannot seem to have an idea how to resolve it on my own.
I have TestNG (6.5.1) + Maven working in Eclipse.  It runs by as I put "testng.xml" as part of the TestNG "Run Configuration" in Eclipse.

But when I try to run it in command-line, it's no longer working. I need to have it in command-line as it will be deployed as part of the Continuous Integration on Jenkins for builds.   

Failure log:
$ mvn3 test

[INFO] Scanning for projects...
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building STest_UnitTest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ STest_UnitTest ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/caps_appserver_qa/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ STest_UnitTest ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ STest_UnitTest ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/caps_appserver_qa/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ STest_UnitTest ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12:test (default-test) @ STest_UnitTest ---
[INFO] No tests to run.
[INFO] Surefire report directory: /tmp/caps_appserver_qa/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
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:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    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: org.testng.TestNGException:
Cannot find class in classpath: com.something.STest.UserTest
    at org.testng.xml.XmlClass.loadClass(XmlClass.java:76)
    at org.testng.xml.XmlClass.init(XmlClass.java:68)
    at org.testng.xml.XmlClass.<init>(XmlClass.java:54)
    at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:523)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:504)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:814)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1320)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2732)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:819)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:392)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
    at org.testng.xml.Parser.parse(Parser.java:170)
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:305)
    at org.testng.TestNG.run(TestNG.java:998)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:177)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:105)
    ... 9 more

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.997s
[INFO] Finished at: Tue Jun 12 15:45:35 PDT 2012
[INFO] Final Memory: 6M/169M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project STest_UnitTest: Error occurred in starting fork, check output in log -> [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/MojoExecutionException


pom.xml:
<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>STest_UnitTest</groupId>
  <artifactId>STest_UnitTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
 
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>me.prettyprint</groupId>
        <artifactId>hector-core</artifactId>
        <version>1.0-3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jettison</groupId>
        <artifactId>jettison</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.5.1</version>
        <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12</version>
                <configuration>
                  <!--   <parallel>methods</parallel>
                  <threadCount>10</threadCount>
                  -->
                  <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                  </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
  </build>
</project>
 
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="AllTest" preserve-order="true">
    <classes>
      <class name="com.something.STest.UserTest" />
    </classes>
  </test> <!-- AllTest -->
</suite> <!-- Suite -->

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/OS3L4QFlVDoJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

SUBRAMANYESWARA RAO BHAVIRISETTY

unread,
Jun 14, 2012, 11:53:14 PM6/14/12
to testng...@googlegroups.com
Hi Sam,

 Please make sure that testng.xml is there in src/test/resources and add the following to pom.xml. This will make sure that testng.xml will be in the classpath

 <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
 </testResources>

and if you run "mvn3 clean install test"  you should be able to run your tests.
Please let me know if you have any issyes.

~Subramanyam

On Wed, Jun 13, 2012 at 9:51 AM, Sam X <s.x...@sta.samsung.com> wrote:
located in test/

Does it have to be in such format like src/test/java?
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/uEpWdWz8Un0J.

To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.



--
Subramanyam

Vittal Manikonda

unread,
Oct 6, 2012, 4:57:51 AM10/6/12
to testng...@googlegroups.com
I am facing similar issue with maven-testng, I am able to run all the methods by eclipse with mvn install,but it is not considering testng.xml ,but when I execute the mvn  -X test I am able to see the following line in log file.


[DEBUG] file testng.xml has a filtered file extension
[DEBUG] filtering C:\Workspace\Bidstrok123_vittal\src\test\resources\testng.xml to C:\Workspace\Bidstrok123_vittal\target\test-classes\testng.xml
[DEBUG] no use filter components

even though i give invalid method name in testng.xml, test running fine as maven is not using my testng.xml .     <groupId>com.Bidstrok123_vittal</groupId>
     <artifactId>Bidstrok123_vittal</artifactId>
     <version>0.0.1-SNAPSHOT</version>
       <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
       </properties>
          <dependencies>
             <dependency>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-java</artifactId>
                    <version>2.25.0</version>
             </dependency>
             <dependency>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-firefox-driver</artifactId>
                    <version>2.25.0</version>

              </dependency>
             <dependency>
                      <groupId>org.testng</groupId>
                      <artifactId>testng</artifactId>
                       <version>6.8</version>
                       <type>jar</type>
               </dependency>
 
          </dependencies>
 
   <build>
    <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
 </testResources>
 
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugin</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.5.1</version>
      <configuration>
            <testSourceDirectory>src/test/java</testSourceDirectory>
          <suiteXmlFiles>
               <suiteXmlFile>${basedir}/src/test/resources/testng.xml</suiteXmlFile>
          </suiteXmlFiles>
          <parallel>methods</parallel>
          <threadCount>1</threadCount>
      </configuration>
    </plugin>
 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
       <version>2.5.1</version>
         <configuration>
          <source>1.7</source>
            <target>1.7</target>

            </configuration>
            </plugin>
            
</plugins>

</build>

</project>
<!-- ${basedir}/src/test/resources/ -->



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="Test">
    <classes>
      <class name="test.LoginTest"/>
   <methods>
                <include name="verifyxyz" />
       
            </methods>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->


regards...
Vittal Manikonda

Krishnan Mahadevan

unread,
Oct 12, 2012, 2:46:55 AM10/12/12
to testng...@googlegroups.com
Change : <suiteXmlFile>${basedir}/src/test/resources/testng.xml</suiteXmlFile>

To: <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>

and see if that helps

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/LTgzzJYvq_cJ.

Vittal Manikonda

unread,
Nov 4, 2012, 5:21:52 AM11/4/12
to testng...@googlegroups.com
No luck with your suggestion . Can you help me more....I am attaching a eclipse product ,please have look and guide me why eclipse is ignoring my testng.xml. I am intentionally given wrong method name in testng.xml.



Regards....
Vittal Manikonda.
Bidstrok123_vittal.zip
Reply all
Reply to author
Forward
0 new messages