You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Krikor Krumlian <kr...@wgbh.org> on 2005/02/25 16:44:27 UTC

Maven , Junit ClassNotFound Exception

Hello everyone ,

using maven 1.0.2
and junit 3.8.1
machine MAC OSX

So i am building this project using maven and i have a unit test that 
i'm trying
to get it to work in maven but so far no luck

my project.xml has this junit dependency defined and nothing else

  <!-- Junit for my unit testing -->
  <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <type>jar</type>
  <properties><war.bundle>false</war.bundle></properties>
  </dependency>

as to the build part it goes as follows

<build>

  <nagEmailAddress>krikor_krumlian@me.org</nagEmailAddress>

  <sourceDirectory>src</sourceDirectory>
  <unitTestSourceDirectory>src/test</unitTestSourceDirectory>


  <!-- Unit test cases -->
  <unitTest>
  <includes>
  <include>**/*Test*.java</include>
  </includes>
  </unitTest>

  </build>

So now building my app using the command maven test:test
gives me the following

__ __
| \/ |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \ ~ intelligent projects ~
|_| |_\__,_|\_/\___|_||_| v. 1.0.2

build:start:

java 

Re: Junit with maven does it work

Posted by Krikor Krumlian <it...@wgbh.org>.
Thank you martijn Dashorst

Figured out my mistake and what was happening , the problem was that in 
my unit tests
I have specified the package name  test , So maven  was putting the 
classes in in test-classes/test/Testxxx.class
and thus it was not finding it later when it needed to test. so when 
you have testcases in the /test/ folder
dont' specify package name.

test:test:
  [junit] Running KkTest
  [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
  [junit] Testsuite: KkTest
  [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
  [junit]
  [junit] Null Test: Caused an ERROR
  [junit] KkTest
  [junit] java.lang.ClassNotFoundException: KkTest
  [junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
  [junit] at java.security.AccessController.doPrivileged(Native Method)
  [junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
  [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
  [junit] at 
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
  [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
  [junit] at 
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
  [junit] at java.lang.Class.forName0(Native Method)
  [junit] at java.lang.Class.forName(Class.java:141)
  [junit]

So if you ever recieve this kind of error while trying to unit test , 
make sure package
names are correct.

things learned

Maven -X debug to check classpath and what not

Thank you all , hope you never do this mistake

Re: Junit with maven does it work

Posted by Martijn Dashorst <ma...@dashorst.dds.nl>.
Krikor Krumlian wrote:

> Hello everyone
>  Has anyone been able to make junit tests work in maven ? If yes
> can you show me the dependency you used maven version and
> the <unitTest> stuff .
>
> It seems so easy and should work but for some reason i have not been
> able to .
>
> thank you
>
>
Try the 'maven genapp' plugin, which will provide you with a Java 
project which has all you need to answer your question(s).

Martijn

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Junit with maven does it work

Posted by Krikor Krumlian <kr...@wgbh.org>.
Thank you martijn Dashorst

Figured out my mistake and what was happening , the problem was that in 
my unit tests
I have specified the package name  test , So maven  was putting the 
classes in in test-classes/test/Testxxx.class
and thus it was not finding it later when it needed to test. so when 
you have testcases in the /test/ folder
dont' specify package name.

test:test:
  [junit] Running KkTest
  [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
  [junit] Testsuite: KkTest
  [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
  [junit]
  [junit] Null Test: Caused an ERROR
  [junit] KkTest
  [junit] java.lang.ClassNotFoundException: KkTest
  [junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
  [junit] at java.security.AccessController.doPrivileged(Native Method)
  [junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
  [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
  [junit] at 
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
  [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
  [junit] at 
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
  [junit] at java.lang.Class.forName0(Native Method)
  [junit] at java.lang.Class.forName(Class.java:141)
  [junit]

So if you ever recieve this kind of error while trying to unit test , 
make sure package
names are correct.

things learned

Maven -X debug to check classpath and what not

Thank you all , hope you never do this mistake

Junit with maven does it work

Posted by Krikor Krumlian <kr...@wgbh.org>.
Hello everyone
  Has anyone been able to make junit tests work in maven ? If yes
can you show me the dependency you used maven version and
the <unitTest> stuff .

It seems so easy and should work but for some reason i have not been
able to .

thank you