{"id":19897,"date":"2018-04-09T07:06:03","date_gmt":"2018-04-09T07:06:03","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=19897"},"modified":"2024-08-05T02:43:54","modified_gmt":"2024-08-05T02:43:54","slug":"how-to-fix-org-testng-testngexception-cannot-find-class-in-classpath","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/how-to-fix-org-testng-testngexception-cannot-find-class-in-classpath\/","title":{"rendered":"How to fix org.testng.TestNGException:  Cannot find class [ Updated 2024 ]"},"content":{"rendered":"<h2>How to fix org.testng.TestNGException<\/h2>\n<p>Let&#8217;s learn how to fix <strong>org.testng.TestNGException<\/strong>: Cannot find a class in the classpath in this post. All the test classes are complied with before they are run. This error indicates that the TestNG does not find the .class file to run the test class.<\/p>\n<h2>Sample Error Trace<\/h2>\n<p>The error has the following stack trace :<\/p>\n<pre>org.testng.TestNGException: \r\nCannot find class in classpath: com.testingdocs.testng.tutorials\r\n.TestNGAnnotationExecutionOrder\r\n\tat org.testng.xml.XmlClass.loadClass(XmlClass.java:75)\r\n\tat org.testng.xml.XmlClass.init(XmlClass.java:67)\r\n\tat org.testng.xml.XmlClass.(XmlClass.java:54)\r\n\tat org.testng.xml.TestNGContentHandler.\r\nstartElement(TestNGContentHandler.java:556)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:518)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:731)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.impl.XMLDocumentFragmentScannerImpl\r\n.scanStartElement(XMLDocumentFragmentScannerImpl.java:1406)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver\r\n.next(XMLDocumentFragmentScannerImpl.java:2725)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.impl.XMLDocumentFragmentScannerImpl\r\n.scanDocument(XMLDocumentFragmentScannerImpl.java:541)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.parsers.XML11Configuration.parse(XML11Configuration.java:888)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.parsers.XML11Configuration.parse(XML11Configuration.java:824)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.parsers.XMLParser.parse(XMLParser.java:141)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)\r\n\tat java.xml\/com.sun.org.apache.xerces.internal\r\n.jaxp.SAXParserImpl.parse(SAXParserImpl.java:324)\r\n\tat java.xml\/javax.xml.parsers.SAXParser.parse(SAXParser.java:197)\r\n\tat org.testng.xml.XMLParser.parse(XMLParser.java:39)\r\n\tat org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16)\r\n\tat org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9)\r\n\tat org.testng.xml.Parser.parse(Parser.java:162)\r\n\tat org.testng.xml.Parser.parse(Parser.java:248)\r\n\tat org.testng.TestNG.parseSuite(TestNG.java:322)\r\n\tat org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:374)\r\n\tat org.testng.TestNG.initializeEverything(TestNG.java:1017)\r\n\tat org.testng.remote.support.RemoteTestNG6_12\r\n.initialize(RemoteTestNG6_12.java:22)\r\n\tat org.testng.remote.AbstractRemoteTestNG\r\n.run(AbstractRemoteTestNG.java:98)\r\n\tat org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)\r\n\tat org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)\r\n<\/pre>\n<h3><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-23507 size-full\" title=\"TestNGException Eclipse\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Exception-Eclipse.png\" alt=\"TestNGException Eclipse\" width=\"1920\" height=\"992\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Exception-Eclipse.png 1920w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Exception-Eclipse-300x155.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Exception-Eclipse-1024x529.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Exception-Eclipse-768x397.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Exception-Eclipse-1536x794.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<h3>Fix<\/h3>\n<p>By default, the test classes are generated under the target folder.<\/p>\n<p>&lt;project_home&gt;\/target\/test-classes<\/p>\n<p>The fix generally depends on the project setup environment, build tool, IDE used etc. If the project is based on Maven using Eclipse IDE, the fix is to clean and update the project.<\/p>\n<p>Check the package names specified in the testng.xml files to the package names in the project. Any mismatch would result in this error. Correct the package names and build the project.<\/p>\n<h2>Example<\/h2>\n<p>For example, in the above screenshot the fully qualified Test class name in the project is:<\/p>\n<p>com.testingdocs.sample.SkipExceptionExample.java<\/p>\n<p>The error was raised because there was a typo in the class name specified in the testng.xml suite file.<\/p>\n<p><strong>The incorrect class name was:\u00a0<\/strong><\/p>\n<p>com.testingdoc.sample.SkipExceptionExample.java<\/p>\n<p>Correct the class name in the testing XML file and clean the project. Run Maven &gt;&gt; Update the project and run the test suite. This error would be resolved.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-23510 size-full\" title=\"TestNG Error Fixed\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Error-Fixed.png\" alt=\"TestNG Error Fixed\" width=\"1917\" height=\"986\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Error-Fixed.png 1917w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Error-Fixed-300x154.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Error-Fixed-1024x527.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Error-Fixed-768x395.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Error-Fixed-1536x790.png 1536w\" sizes=\"auto, (max-width: 1917px) 100vw, 1917px\" \/><\/p>\n<h2>TestNG Tutorials<\/h2>\n<p>TestNG Tutorials on this website can be found at:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.testingdocs.com\/testng-framework-tutorial\/\">https:\/\/www.testingdocs.com\/testng-framework-tutorial\/<\/a><\/li>\n<\/ul>\n<p>For more details on the TestNG Framework, visit the official website of TestNG at:<\/p>\n<ul>\n<li><a href=\"https:\/\/testng.org\" target=\"_blank\" rel=\"noopener\">https:\/\/testng.org<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>How to fix org.testng.TestNGException : Let&#8217;s learn how to fix org.testng.TestNGException: Cannot find a class in the classpath in this post. All the tests classes<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[213],"tags":[],"class_list":["post-19897","post","type-post","status-publish","format-standard","hentry","category-testng","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/19897","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=19897"}],"version-history":[{"count":15,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/19897\/revisions"}],"predecessor-version":[{"id":23514,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/19897\/revisions\/23514"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=19897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=19897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=19897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}