Properly defining classpath

1,450 views
Skip to first unread message

Raider Power

unread,
Dec 16, 2009, 5:11:00 PM12/16/09
to testng-users
Apologies to all for a repetition of a question regarding classpath,
but I have been having a heck of a time getting a simple test to run
from a command line with testng. Below is a description of what I am
seeing:

I decided to try using the example on testng.org home page to get me
started. In Eclipse, the package and class are in my project as shown
below:

Project: Sandbox
Source folder: sandboxSrc
Package: example1
Java Source File: SimpleTest.java
Class: SimpleTest

The directory for my workspace is C:\Documents and Settings\myid
\workspace\Sandbox\sandboxSrc\example1. testng is in my eclipse
environment at C:\eclipse\plugins\org.testng.eclipse_5.11.0.21\lib
\testng-jdk15.jar.

When I run the test through eclipse, a file called temp-testng-
customsuite.xml is built that looks like what is listed below:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Sandbox">
<test verbose="2" name="example1.SimpleTest" annotations="JDK">
<classes>
<class name="example1.SimpleTest"/>
</classes>
</test>
</suite>

I can run the test through eclipse with no issues. I then take the
above xml file and copy the contents to testng.xml. Next I open a
command window and set the classpath as follows:

set CLASSPATH=C:\eclipse\plugins\org.testng.eclipse_5.11.0.21\lib
\testng-jdk15.jar;C:\Documents and Settings\myid\workspace\Sandbox
\sandboxSrc\example1

Finally within the command window, I enter java org.testng.TestNG
testng.xml. The following is the result:

[Parser] Running:
C:\Documents and Settings\myid\workspace\Sandbox\testng.xml


[ClassHelper] Could not instantiate example1.SimpleTest:
example1.SimpleTest
[ClassHelper] Could not instantiate example1.SimpleTest:
example1.SimpleTest

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

org.testng.TestNGException:
Cannot find class in classpath: example1.SimpleTest
at org.testng.xml.XmlClass.getSupportClass(XmlClass.java:55)
at org.testng.internal.Utils.xmlClassesToClasses(Utils.java:
79)
at org.testng.TestRunner.initMethods(TestRunner.java:298)
at org.testng.TestRunner.init(TestRunner.java:244)
at org.testng.TestRunner.init(TestRunner.java:206)
at org.testng.TestRunner.<init>(TestRunner.java:151)
at org.testng.SuiteRunner
$DefaultTestRunnerFactory.newTestRunner(SuiteRu
nner.java:483)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:247)
at org.testng.SuiteRunner.run(SuiteRunner.java:201)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:915)
at org.testng.TestNG.runSuitesLocally(TestNG.java:879)
at org.testng.TestNG.run(TestNG.java:787)
at org.testng.TestNG.privateMain(TestNG.java:952)
at org.testng.TestNG.main(TestNG.java:925)

Admittedly, I am not a java expert by any stretch, so I have been
trying to make sure I understand how a classpath should be setup
properly in java so that I can make this work. I suspect I am missing
something simple, but cannot put my finger on it.

I would be most appreciative of any help you can provide. Please let
me know if any additional information is required to further describe
this issue. Thanks.

RP.

Carsten

unread,
Dec 20, 2009, 7:45:56 PM12/20/09
to testng-users
Your classpath looks incorrect: C:\Documents and Settings\myid
\workspace\Sandbox\sandboxSrc\example1

1. is sandboxSrc your output-directory or only your source directory
2. do not add the package example1 to your classpath but only the
output directory

Reply all
Reply to author
Forward
0 new messages