You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Joshi, Yogesh (Cognizant)" <Yo...@pun.cognizant.com> on 2003/09/26 08:24:35 UTC

Regarding Unit testing in Maven

Hi ,

I am using Maven for the first time for 'Unit Testing'. I am not very clear about how it exactly works.
As far as I know, Maven has a in built plugin for JUnit and we need to provide the <unitTestSourceDirectory>
in Project.xml. However if for,e.g., SampleTest.java is expected to test SampleMaven.java, then how the individual methods are going to be tested ? How are we going to pass the parameters ? shall we call every method individually ?

I am sorry for asking such a basic question but I have never worked in this regard.
I tried to use Unit testing feature but getting some errors as below:

test:test-resources:

test:compile:
    [javac] Compiling 1 source file to D:\SampleMaven\target\test-classes

test:test:
    [junit] dir attribute ignored if running in the same VM
    [junit] Running MavenTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] [ERROR] TEST MavenTest FAILED

BUILD FAILED
File...... file:/C:/Documents and Settings/104487/.maven/plugins/maven-test-plug
in-1.3/
Element... fail
Line...... 99
Column.... 54
There were test failures.
Total time:  21 seconds

Log under 'testreports' says :
java.lang.ClassNotFoundException: MavenTest
	at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:186)


Attached with this is my Project.xml, Source and Test files.



Thanks a lot in advance,
Yogesh




Re: Regarding Unit testing in Maven

Posted by Andy Jefferson <an...@ajsoft.net>.
On Friday 26 Sep 2003 07:24, Joshi, Yogesh (Cognizant) wrote:
> I am using Maven for the first time for 'Unit Testing'. I am not very clear
> about how it exactly works. As far as I know, Maven has a in built plugin
> for JUnit and we need to provide the <unitTestSourceDirectory> in
> Project.xml. However if for,e.g., SampleTest.java is expected to test
> SampleMaven.java, then how the individual methods are going to be tested ?
> How are we going to pass the parameters ? shall we call every method
> individually ?

I'd suggest that you familiarise yourself with JUnit. ... www.junit.org. What 
you basically need is to define your test files to contain methods called
testXYZ(). The name XYZ has does not need to have any relation to the 
class(es) you are testing ... it is a name only.

Any method called that will be called by JUnit. You can include methods 
setUp() and tearDown() in the Test class as well to set up things that you 
need in your testXYZ() methods. It is customary to terminate each testXYZ 
method with an assert(status) to return to Junit what the result of the test 
is.



-- 
Andy


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