[ERROR]:
===============================================
Cannot find class in classpath: persistence.test.UpdatableEntityTest
PersistenceTests
Total tests run: 0, Failures: 0, Skips: 0
===============================================
However, I know that class is in the classpath! Here is how I know
(from Ant in verbose mode):
testng
Executing 'C:\Program Files\Java\jdk1.5.0_12\jre\bin\java.exe' with
arguments:
'-ea'
'-classpath'
'[Bunch of standard jars];
C:\persistence\classes\persistence\UpdatableEntity.class;
C:\persistence\classes\persistence\admin\User.class;
C:\persistence\classes\persistence\test\UpdatableEntityTest.class'
'org.testng.TestNG'
Here is the Ant task:
<testng classpathref="task.class.path.libs"
outputDir="${testng.report.dir}"
haltOnfailure="true">
<xmlfileset dir="${testng.suite.dir}"
includes="persistenceTests.xml" />
</testng>
What am I missing here?
Thanks for any insight.
Here is my classpath:
<path id="testng.class.path.lib">
<fileset dir="${testng.lib.dir}"/>
</path>
<path id="dbunit.class.path.lib">
<fileset dir="${dbunit.lib.dir}"/>
</path>
<path id="task.class.path.libs">
<path refid="testng.class.path.lib"/>
<path refid="dbunit.class.path.lib"/>
<fileset dir="${seam-hibernate.lib.dir}" includes="jboss-
seam.jar"/>
<fileset dir="${oracle.lib.dir}" />
<fileset dir="${build.dir}" /> <!-- This is the top level
directory below which my compiled classes reside. I get the same
error whether I have this entry here or not. -->
</path>
----------------------------------------
Just for kicks, here is my XML file:
<suite name="PersistenceTests">
<test name="UpdatableEntityTest">
<groups>
<run>
<include name="updatableEntityTest"/>
</run>
</groups>
<classes>
<class name="persistence.test.UpdatableEntityTest" />
</classes>
</test>
</suite>
---------------------------
I know this all seems rudimentary, particulalry for you as the father
of TestNG, but I really would appreciate some guidance.
Thanks again.
I will try your approach, Cedric, and see what I find.
Thank you both for your help. Meanwhile, if anyone else sees
something silly I might be doing, please feel free to point it out.
On Oct 23, 8:41 pm, "Mark Derricutt" <m...@talios.com> wrote:
> SIlly question I know - but you are actually annotation your test methods
> with @Test right?
>
build
--persistence
-----test
--------UpdatableEntityTest.class
So I was doing things like this in the classpath
<fileset dir="${build.dir}" includes="**/*.class"/>
or
<fileset dir="${build.dir}" />
or
no entry at all.
Hopefully, that at least clears up the directory content issue.
Now on to try Cedric's command line suggestion.
Thanks.
I did so this way:
java -cp C:\persistence\dist\persistence.jar -jar testng-5.6-
jdk15.jar C:\persistence\test\suites\persistenceTests.xml
I also tried without a JAR:
java -cp C:\persistence\build -jar testng-5.6-jdk15.jar C:\persistence
\test\suites\persistenceTests.xml
and
java -cp C:\persistence\build\persistence -jar testng-5.6-jdk15.jar C:
\persistence\test\suites\persistenceTests.xml
and
java -cp C:\persistence\build\persistence\test -jar testng-5.6-
jdk15.jar C:\persistence\test\suites\persistenceTests.xml
----------------
Any hints?
Thanks.
java -cp C:\persistence\build -jar testng-5.6-jdk15.jar -testclass
persistence.test.UpdatableEntityTest
I got a slightly different error: Cannot load class from file:
persistence.test.UpdatableEntityTest
Incidentally, the directory "build" mentioned above is a directory
below which all my packages and .class files, including my test class,
are located.
Is this simply another way of saying the same error I received
before? Or am I getting any closer?
--
Cédric
--
Cédric
java -cp testng-5.6-jdk15.jar;C:\persistence\build org.testng.TestNG -
testclass persistence.test.UpdatableEntityTest
I still get this:
Exception in thread "main" org.testng.TestNGException:
Cannot load class from file: persistence.test.UpdatableEntityTest
at
org.testng.TestNGCommandLineArgs.fileToClass(TestNGCommandLineArgs.ja
va:603)
at
org.testng.TestNGCommandLineArgs.parseCommandLine(TestNGCommandLineAr
gs.java:225)
at org.testng.TestNG.privateMain(TestNG.java:815)
at org.testng.TestNG.main(TestNG.java:802)
Did you have something else in mind for me to try?
--------------------------------------------
Going back to Ant, I did some restructuring:
<path id="testng.class.path.lib">
<fileset dir="${testng.lib.dir}"/> contains testng.jar
</path>
<path id="dbunit.class.path.lib">
<fileset dir="${dbunit.lib.dir}"/> contains dbunit.jar
(irrelevant to this issue)
</path>
<path id="database.class.path.libs">
<path refid="dbunit.class.path.lib"/>
<fileset dir="${oracle.lib.dir}" /> contains Oracle
driver (irrelevant to this issue)
</path>
<path id="tests.class.path.libs">
<path refid="testng.class.path.lib"/>
<path refid="database.class.path.libs"/>
<fileset dir="${seam-hibernate.lib.dir}" includes="jboss-
seam.jar"/> contains jboss-seam.jar for SeamTest class
(irrelevant to this issue)
<fileset dir="${build.dir}" /
>
contains .class file hierarchy compiled from source
</path>
And here is the Ant task
<testng classpathref="tests.class.path.libs" outputDir="$
{testng.report.dir}" failureProperty="test.failed">
<xmlfileset dir="${testng.suite.dir}"
includes="persistenceTests.xml" />
</testng>
Anything jump out here?
Thanks.
Here is the statement again:
java -cp testng-5.6-jdk15.jar;C:\persistence\build org.testng.TestNG -
testclass persistence.test.UpdatableEntityTest
Let me see if this is clearer:
java
-cp testng-5.6-jdk15.jar;C:\persistence\build
org.testng.TestNG
-testclass persistence.test.UpdatableEntityTest
As you can see here, the only "jar" in the line was where I place
"testng-5.6-jdk15.jar" in the classpath with -cp. I can see how it
might be hard to catch that given how the command appears on here.
The other item in the classpath is the top level directory below which
my .class files reside.
Seemed reasonable to me.
Also, you said this
"Try this: find the right classpath so that
java -classpath directory persistence.test.UpdatableEntityTest
will find your class. "
But in your last message you said to use "javap." I know that is an
actual command, but I imagine that was a typo since I am not sure how
the command would be relevant here. Is that correct?
I can understand your point that this is more Java classpath stuff
than it is TestNG stuff, but I have managed to get things like DBUnit
and Hibernate Tools (which require way more configuration) going in
Ant. I am not suggesting Al Gore should give me his Nobel Prize for
those achievements, but it is really troubling that I can't get
something so basic right with TestNG. That is why I am curious if
there is something peculiar about how it handles things. Particularly
given that I think that everything I have tried in my Ant script is
really quite reasonable.
If anyone has any working examples of getting TestNG to work in Ant, I
would really appreciate some Ant target samples and maybe a brief
explanation of how you handled the test classes themselves.
Thanks.
Oh well, cryptic and misleading error messages aside, I seem to be
moving along nicely.
Thanks to all.
When you use the -jar param on the command line, java.exe ignores the
classpath; the only classpath it uses is what is specified in the
Classpath: entry in the JAR's manifest. Ant's <java> task warns of
this, because we make the same mistake ourselves, but java.exe doesnt
bother, because it should be so obvious.
Options
-Add the testng jar to the CP, give the main entry point by hand.
-create a manifest in your test jar, point to testng
> I got a slightly different error: Cannot load class from file:
> persistence.test.UpdatableEntityTest
>
> Incidentally, the directory "build" mentioned above is a directory
> below which all my packages and .class files, including my test class,
> are located.
>
> Is this simply another way of saying the same error I received
> before? Or am I getting any closer?
The error has moved
Ahhh - I actually have a patch for TestNG to report such dependency problems (and optionally ignore them when trying to find classes), I must tidy that up and send it over to Cedric/Alex to consider.