Issue 43: [ClassHelper] Could not instantiate com.company.product.test.mail.MailPdfTest
Status:  New
Owner: ----
Reported by ralf.hau...@gmail.com, Feb 4, 2009
What steps will reproduce the problem?
1. run a test case after another develper with committ rights changed a
.jar or alike.

What is the expected output? 
   The test case is executed OR there is an error message that better helps
resolving the problem

What do you see instead?
<<Parser] Running:
  /home/dev/workspace/proj1/temp-testng-customsuite.xml

[ClassHelper] Could not instantiate
com.company.product.test.mail.MailPdfTest:
com.company.product.test.mail.MailPdfTest
[ClassHelper] Could not instantiate
com.privasphere.privalope.test.mail.MailPdfTest:
com.privasphere.privalope.test.mail.MailPdfTest

===============================================
testPSPH
Total tests run: 0, Failures: 0, Skips: 0
===============================================

org.testng.TestNGException: 
Cannot find class in classpath: com.company.product.test.mail.MailPdfTest
	at org.testng.xml.XmlClass.getSupportClass(XmlClass.java:55)
	at org.testng.internal.Utils.xmlClassesToClasses(Utils.java:76)
	at org.testng.TestRunner.initMethods(TestRunner.java:281)
	at org.testng.TestRunner.init(TestRunner.java:227)
	at org.testng.TestRunner.init(TestRunner.java:189)
	at org.testng.TestRunner.<init>(TestRunner.java:150)
	at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:102)
	at
org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:154)
	at
org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:517)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:244)
	at org.testng.SuiteRunner.run(SuiteRunner.java:198)
	at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:823)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:790)
	at org.testng.TestNG.run(TestNG.java:708)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124>>  

What version of the product are you using? On what operating system?
- TestNG 5.8.0.2
- Debian stable
- Eclipse 3.2.1


Please provide any additional information below.

Since the eclipse test project has dependencies to the real product eclipse
project and each test-case can have its own class-path as well, it would be
very helpful if 
1) this error would also print out the classpath it is searching on as well as 
2) the System.getProperty("user.dir") in case there are relative paths
3) the error would name the entity that defines the class-path (test-case,
project, depentent project X, ...)
4) if the classloader cascades through multiple class-paths list them
individually ...
Apr 2, 2009
#1 machineg...@gmail.com
This has happened to me under other conditions (ie. no other dev changed my JARs),
but I haven't been able to nail down what those conditions are exactly, as the issue
appears to occur randomly.  One day I'll be able to run tests in Eclipse fine, then
later that day, without any changes to my classpaths or anything, every test I try
and run will get the dreaded "[ClassHelper] Could not instantiate ...".  It's REALLY
frustrating (and I wish I could provide more help in tracking the issue down, but
unfortunately due to its sporadic nature I can't).
Apr 2, 2009
#2 machineg...@gmail.com
P.S. I have found that when this issue occurs using Project => Clean and/or
restarting Eclipse can sometimes (but not always) resolve it.  Perhaps you could
simply modify the plug-in such that when it runs and fails to find anything on the
classpath, it does whatever cleaning/restarting Eclipse does ("behind-the-scenes"),
and then retries?
Jun 19, 2009
#3 dfran...@gmail.com
Project => Clean worked for me too.  Thanks!
Oct 27, 2009
#4 amjedonline@gmail.com
This happens in the following condition:
1. Your test case project is depending on other eclipse project ( could be through
maven dependency)
2. The dependent project has build/compilation errors.

In this case, when you try to run the test case, maven eclipse plugin tries to build
the dependent projects, and when it fails doing so, it stops building your project,
and hence does not create class file for you test case.

Solution:
1.Close the other project, so that eclipse satisfies the project dependecy from the
repository and not from the eclipse project.
2. Remove the build/compilation errors from the other project ( see the problems view
for help)

Dec 18, 2009
#5 machineg...@gmail.com
That is not the only condition under which it happens.  I just saw it happen now when
I only had a single project open.
Dec 18, 2009
#6 machineg...@gmail.com
Just figured out another thing that can cause this (and therefore another work
around).  I had a build path error (that I found in the "Problems" tab) due to a
library that I'd specified in my project's build path, but which had since been
deleted in the file system.  Once I removed this library from my build path, I was
able to build (and see a bunch of other errors in my project), and it also made it so
that I could actually run tests again.  Hope this helps someone.
Aug 2, 2010
#8 Sereb...@gmail.com
I fixed this problem by re-installing the TestNG plugin, refreshing & cleaning the build.
None of the solutions above worked for me before re-installing the plugin.

Hope it helps someone.
Oct 19, 2010
#9 tej...@google.com
Got this problem because i had renamed the test file. And this new name was not reflecting in the classpath of eclipse.

Tried all the above solutions but it didn't helped.
Fixed this problem by restarting the eclipse and then cleaning the project..


Oct 28, 2010
#10 ondrej.s...@gmail.com

I had also this problem. For me worked rebuilding project with maven "clean install" parameter, with Skip tests NOT cheched (so that tests are run before build - they must be successfull otherwise it has no effect). After this, tests started to work again properly.
Nov 5, 2010
#11 ikara...@gmail.com
for me it happened when I switched from one branch to another in git and forgot to refresh the source tree
Dec 7, 2010
#12 jim.cl...@gmail.com
We have had this same problem and it is intermittent here as well.  There is a simple, yet unexplainable fix.  Open the .project file in an editor and remove the line <nature>org.maven.ide.eclipse.maven2Nature</nature> from the <natures> section.  mvn eclipse:eclipse seems to, only sometimes, insert this line into natures.  When it does so, TESTNG exhibits this weird behavior.  Good luck.
Feb 16, 2011
#13 dfran...@gmail.com
Ugh.  I tried all the above (which has in past worked), didn't work. What worked this time was:

mvn eclipse:clean
mvn eclipse:eclipse

Then clean, then rebuild.

Mar 8, 2011
#14 nathanan...@gmail.com
Comment 6 was most applicable to me. As soon as I removed the missing jar from the build path it worked a treat. The annoying thing in this situation, then, was that the error message had no relation to the problem at hand.
May 18, 2011
#15 aashish....@gmail.com
Comment 13 worked for maven projects...
Aug 3, 2011
#16 bitingsp...@gmail.com
Yep, "Project > Clean" worked for me. Frustrating morning till I found the answer here. Thanks everyone.
Nov 3, 2011
#17 nor777...@gmail.com
I had not qualified my class names in testng.xml with the package name, which caused testng not to find them. Adding the package name solved it for me.

before:   <class name="MyClass"/>
after:    <class name="myPackage.MyClass"/>
Nov 10, 2011
#20 doulat.k...@gmail.com
I had the same problem and the typo was same as comment#17. Adding my package name worked for me!

class name="mypackage.myclass"
Nov 10, 2011
Project Member #21 cbe...@gmail.com
If you have any other problems, please file a new issue on http://github.com/cbeust/testng-eclipse.

Jan 12, 2012
#22 Syed.Bi...@gmail.com
Nothing above worked for me. 
I solved this issue by 

>eclipe.rebuild.cmd
and from eclipse, did clean and rebuild. 
Apr 15, 2012
#23 vietabhi...@gmail.com
i am using testng 6.3.1, when i run the project i see message in console

org.testng.TestNGException: 
Cannot instantiate class com.qait.testframework.Gale.AppTest
	at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:38)
	at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:374)
	at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:286)
	at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:110)
	at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:195)
	at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:120)
	at org.testng.TestRunner.initMethods(TestRunner.java:405)
	at org.testng.TestRunner.init(TestRunner.java:231)
	at org.testng.TestRunner.init(TestRunner.java:201)
	at org.testng.TestRunner.<init>(TestRunner.java:157)
	at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:139)
	at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:269)
	at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:562)
	at org.testng.SuiteRunner.init(SuiteRunner.java:157)
	at org.testng.SuiteRunner.<init>(SuiteRunner.java:111)
	at org.testng.TestNG.createSuiteRunner(TestNG.java:1216)
	at org.testng.TestNG.createSuiteRunners(TestNG.java:1203)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1057)
	at org.testng.TestNG.run(TestNG.java:978)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
	... 21 more
Caused by: java.lang.NoClassDefFoundError: com/google/common/base/Function
	at com.qait.testframework.Gale.PageUI.<init>(PageUI.java:16)
	at com.qait.testframework.Gale.AppTest.<init>(AppTest.java:12)
	... 26 more
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	... 28 more
please suggest me which version of testng is best for me to reslove this....

Thanks
Abhishek Verma
Aug 22, 2012
#24 shwethhh...@gmail.com
Hi, 

i faced the same problem so many times. Sometimes as others mentioned by closing the other projects and project-> Clean.

Since I am automating selenium in which I had the reference to excel sheet and it was open for long time.Since I closed and opened eclipse maybe be some reference is lost or not sure. It worked when I closed the excel sheet and clean the project. 
Nov 5, 2012
#25 mangesh....@gmail.com
I try above all comments but it doesn't help me.
Could any baddie have any other idea 
Nov 13, 2012
#26 sendamil...@gmail.com
It seems there is a problem regarding testng and maven, at least, for my case. 
I tried to configure the project that it was failing to maven nature, and then eclipse throws an error. Then I execute mvn eclipse:clean and mvn eclipse:eclipse. And it starts to work, but it's a strange error. 
I think it's not related to testng because some colleagues only use junit and they have had the same problem.
I hope this helps you. 
Sep 25, 2013
#27 fa...@provasolutions.com
nothing above worked for me guys         please help me

Sep 15, 2014
#28 manukeer...@gmail.com
Hi guys,

I am facing same issue.Tried all above solutions but no luck
Oct 12, 2014
#29 sravan.g...@gmail.com
Cannot find class in classpath: com.slokam.wd.Example1
	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:543)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
	at javax.xml.parsers.SAXParser.parse(Unknown Source)
	at org.testng.xml.XMLParser.parse(XMLParser.java:39)
	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:168)
	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:17

in the first maven project i got the issue.Again i create a new maven project add all dependecies. if i run the script got same problem...how can i rectify. The issue is in my PC or eclipse
Feb 6, 2015
#30 revathii...@gmail.com

How to solve the below error.. 

org.testng.TestNGException: 
Cannot instantiate class Testcases
	at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:38)
	at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:387)
	at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:299)
	at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:110)
	at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:186)
	at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:120)
	at org.testng.TestRunner.initMethods(TestRunner.java:409)
	at org.testng.TestRunner.init(TestRunner.java:235)
	at org.testng.TestRunner.init(TestRunner.java:205)
	at org.testng.TestRunner.<init>(TestRunner.java:160)
	at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:141)
	at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:271)
	at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:561)
	at org.testng.SuiteRunner.init(SuiteRunner.java:157)
	at org.testng.SuiteRunner.<init>(SuiteRunner.java:111)
	at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)
	at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
	at org.testng.TestNG.run(TestNG.java:1057)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
	... 21 more
Caused by: java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTSheet
	at Regression.Xlsx_Reader.<init>(Xlsx_Reader.java:61)
	at Regression.Testcases.<init>(Testcases.java:15)
	... 26 more
Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 28 more

Mar 24, 2015
#31 anbukris...@gmail.com
PLz help me out i stuck with below error


[TestNG] Running:
  C:\Users\bharathk1\AppData\Local\Temp\testng-eclipse--545375835\testng-customsuite.xml

FAILED CONFIGURATION: @BeforeTest launchBrowser
java.lang.NullPointerException
	at tests.my1st.launchBrowser(my1st.java:23)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
	at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
	at org.testng.TestRunner.beforeRun(TestRunner.java:641)
	at org.testng.TestRunner.run(TestRunner.java:609)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
	at org.testng.SuiteRunner.run(SuiteRunner.java:240)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
	at org.testng.TestNG.run(TestNG.java:1057)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

SKIPPED CONFIGURATION: @AfterTest closingBrowser
SKIPPED: verfyHomepageTitle

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================

[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 9 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@6b2d4a: 13 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@ac736f: 6 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@6f3b58: 65 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@ec6354: 39 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@1ee0005: 5 ms
Picked up _JAVA_OPTIONS: -Xmx512M