You don't have your classes (tests & target classes) on the classpath.
views:
1462answers:
3I realize I may be hijacking this thread but classpath is a source of great confusion for me. I (now) understand that TestNG's classpath is not the same as the Java classpath but I can't seem to get my classpath configured correctly. All the docs I've seen online mention how easy and straightforward it is to use ant to drive TestNG but I am baffled.
Every time I try I get an exception from TestNG saying it can't find the class I'm trying to test in the classpath. I have no idea why.
Here is my ant build script:
<project>
<property name="TOOLS_DIR" value=".."/>
<property name="TOOLS_LIB_DIR" value="${TOOLS_DIR}/lib"/>
<property name="TOOLS_SRC_DIR" value="${TOOLS_DIR}/src"/>
<property name="TOOLS_BIN_DIR" value="${TOOLS_DIR}/bin"/>
<property name="TOOLS_RESOURCES_DIR" value="${TOOLS_DIR}/resources"/>
<property name="TOOLS_BUILD_DIR" value="${TOOLS_DIR}/build"/>
<property name="TOOLS_STAGING_DIR" value="${TOOLS_BUILD_DIR}/staging"/>
<property name="TOOLS_ARTIFACTS_DIR" value="${TOOLS_STAGING_DIR}/artifacts"/>
<property name="TEST_RESULTS_DIR" value="${TOOLS_STAGING_DIR}/test_results"/>
<property name="TOOLS_GENLIB_DIR" value="${TOOLS_DIR}/gen-lib"/>
<!-- Test Classpath -->
<path id="test-classpath">
<fileset dir="${TOOLS_LIB_DIR}">
<include name="*.jar"/>
</fileset>
<fileset dir="${TOOLS_BIN_DIR}">
<include name="**/*.class"/>
</fileset>
<fileset dir="${TOOLS_SRC_DIR}">
<include name="**/*.java"/>
</fileset>
<pathelement location="C:\dev\depot\bas\projects\venture.3\batools\bin\tv\ba\tools\gui\APTtest\PlatformTest.class" />
<pathelement location="C:\dev\depot\bas\projects\venture.3\batools\src\tv\ba\tools\gui\APTtest\PlatformTest.java" />
</path>
<taskdef resource="testngtasks" classpath="C:\dev\depot\bas\projects\venture.3\batools\lib\testng-5.11-jdk15.jar"/>
<target name="compile">
<echo message="Tools bin dir = ${TOOLS_BIN_DIR}"/>
<mkdir dir="${TOOLS_BIN_DIR}"/>
<mkdir dir="${TOOLS_ARTIFACTS_DIR}"/>
<mkdir dir="${APT_TOOL_DIR}"/>
<mkdir dir="${APT_TOOL_DIR}/META-INF"/>
<mkdir dir="${TEST_RESULTS_DIR}"/>
<javac srcdir="C:\dev\depot\bas\projects\venture.3\batools\src\tv\ba\tools\gui\APTtest" destdir="${TOOLS_BIN_DIR}" debug="on" encoding="UTF-8">
<classpath refid="test-classpath"/>
</javac>
</target>
<target name="manifest_APT_Platform_test">
<manifest file= "${APT_TOOL_DIR}/META-INF/MANIFEST.MF" mode="update">
<attribute name="Main-Class" value="tv.ba.tools.gui.APTtest.PlatformTest"/>
</manifest >
</target>
<target name="APT_Platform_tool" depends="compile,manifest_APT_Platform_test">
<jar destfile="${TOOLS_ARTIFACTS_DIR}/APT_Platform_tool.jar" basedir="${APT_TOOL_DIR}" manifest="${APT_TOOL_DIR}/META-INF/MANIFEST.MF" />
<!-- <delete dir="${APT_TOOL_DIR}" /> -->
</target>
<target name="test" depends="compile" description="Run all tests defined in PlatformTest.class.">
<testng classpathref="test-classpath"
outputDir="${TEST_RESULTS_DIR}/${DSTAMP}.${TSTAMP}-single-test-${class.name}-${test.name}"
workingDir="${TEST_RESULTS_DIR}/${DSTAMP}.${TSTAMP}-single-test-${class.name}-${test.name}"
verbose="7"
useDefaultListeners="true">
<classfileset dir="C:\dev\depot\bas\projects\venture.3\batools\bin\tv\ba\tools\gui\APTtest" includes="PlatformTest.class"/>
<xmlfileset dir="." includes="TestNG_Driver_2.xml" />
<jvmarg value="-Xmx1024m"/>
</testng>
</target>
Here is my TestNG Config file (TestNG_Driver_2.xml)
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Venture.3.batools" verbose="7">
<test name="APTUserAdminTest" verbose="6" annotations="JDK">
<classes>
<class name="tv.ba.tools.gui.APTtest.PlatformTest">
<methods>
<include name="*" />
</methods>
</class>
</classes>
</test>
</suite>
When I run this all with ant TestNG can't find the class I want to test. It seems to find the TestNG files but even with the class under test specifically referenced and listed in the test-classpath variable it never finds PlatformTest.class.
test:
[echo] Start test
[testng] Exception in thread "main" org.testng.TestNGException:
[testng] Cannot load class from file: C:\dev\depot\bas\projects\venture.3\batools\bin\tv\ba\tools\gui\APTtest\PlatformTest.class
[testng] at org.testng.TestNGCommandLineArgs.fileToClass(TestNGCommandLin
eArgs.java:694)
[testng] at org.testng.TestNGCommandLineArgs.parseCommandLine(TestNGComma
ndLineArgs.java:228)
[testng] at org.testng.TestNG.privateMain(TestNG.java:943)
[testng] at org.testng.TestNG.main(TestNG.java:925)
Frustratingly, I don't know enough about ant or TestNG to tell if there's something huge I'm omitting. I just don't get it.