6

When I am trying to run the test suite, am getting this exception on Mac, we are using maven projects here, today morning eclipse was hung and i done force quit and then restarted the same and later am not able to run the tests. I done refreshing, cleaning, reinstalling testNG, reconfigured eclipse with the new eclipse instance and imported the maven projects but then also am getting the same exception..The same maven projects ll run on the other Mac, Pls suggest any ways tat am missing here.

also referred the solutions present in the following links : SO link 1 SO link 2

Error console :

org.testng.TestNGException: 
Cannot find class in classpath: com.adobe.store.polarBear.polarBearSuite.tests.ReaderAIHTest
    at org.testng.xml.XmlClass.loadClass(XmlClass.java:81)
    at org.testng.xml.XmlClass.init(XmlClass.java:73)
    at org.testng.xml.XmlClass.<init>(XmlClass.java:59)
    at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:539)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:788)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2756)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:1)
    at org.testng.xml.Parser.parse(Parser.java:172)
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Community
  • 1
  • 1
harish raja
  • 61
  • 1
  • 1
  • 2

7 Answers7

7

Go to Project --> Clean

It works for me

bugCracker
  • 3,656
  • 9
  • 37
  • 58
2

Couple of suggestions : 1. Go to your target folder and check whether the .class for ReaderAIHTest is available? 2. Go to Run As - > Maven Build -> Enter goal as clean test-compile (I am assuming your cases are lying in src/test/java. )

niharika_neo
  • 8,441
  • 1
  • 19
  • 31
1

I faced the same problem. After syncing code from repo when i refreshed my project in eclipse. Package name start to show from src.test.java.com......

so the whole problem is .classpath file in your module directory Do 'mvn eclipse:eclipse' it will regenerate your module's '.classpath' file. And then refresh your project in eclipse.

Bharat Bhagat
  • 381
  • 1
  • 5
  • 14
  • Can you please explain this in little more detail? I am using IntelliJ IDEA and had to refresh my project recently but since refreshing I am facing org.testng.TestNGException Cannot find class in classpath exception. – SelThroughJava Jan 24 '17 at 05:20
  • I think you should try this command from root directory of your project `mvn idea:idea` in case of Intellij. and then reimport your project. If you are using any other build tool, then all you need to figure out how to regenerate intellij idea hidden files – Bharat Bhagat Jan 24 '17 at 06:30
1

For IntelliJ Idea, after re-building the project use command : mvn idea:idea

After Build success, the exception "Cannot find class in classpath" is resolved.

palslav
  • 11
  • 1
0

Are you using 'Run configurations' feature in eclipse ? If so, make sure you are using the correct testng.xml for the test you are trying to run. Sometimes you are using the wrong one or one that was autocreated in the 'Run Configurations' menu in eclipse.

0

if your package name is TEST_Package and class name is DEMO_TEST then the code in xml should be

classes
class name="TEST_Package.DEMO_TEST"
classes

you will try this......it will work

CSchulz
  • 10,882
  • 11
  • 60
  • 114
0

For me, it was configured a wrong "Project compiler output". Go to File > Project Structure > Project compile output > Click in "..." > Choose a folder

Pedro Rosanes
  • 70
  • 1
  • 6