Discussion:
How to add classpath to JUnit Tests
Steve Garcia
2003-05-30 17:12:04 UTC
Permalink
I wish to add additional classpath entries when I run

maven test

because there are additional resources that must be present in the classpath. For instance
I am generating test cases that test ResourceBundles, so I need the .properties files in the
classpath. How can I accomplish this?

Thanks, Steve
Alex Vollmer
2003-05-30 17:23:08 UTC
Permalink
You can do this by adding a <resources> stanza to your <unitTests>
declaration in your project.xml. For example...

<unitTest>
<includes>
<include>**/*Test.java</includes>
</includes>
<resources>
<resource>
<directory>src/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</unitTest>

The only problem I've seen with this is that the 'test:test-resources'
task doesn't seem to execute this if you invoke this project from
another one using Reactor (can anyone shed some light on this?). So the
other way you could do it is to add a <postGoal> definition to the
maven.xml file (same directory as your project.xml) that looks like this:

<postGoal name="test:compile">
<ant:copy dir="${maven.build.dir}/test-classes">
<ant:fileset dir="${basedir}/src/java">
<ant:includes>
<ant:include name="**/*.properties"/>
</ant:includes>
</ant:fileset>
</ant:copy>
</postGoal>

Either way, the net effect is to put these files in the
target/test-classes directory so that when you run your unit-tests these
files show up in the CLASSPATH.

--Alex
Post by Steve Garcia
I wish to add additional classpath entries when I run
maven test
because there are additional resources that must be present in the classpath. For instance
I am generating test cases that test ResourceBundles, so I need the .properties files in the
classpath. How can I accomplish this?
Thanks, Steve
---------------------------------------------------------------------
Michal Maczka
2003-05-30 17:28:33 UTC
Permalink
It is usually good idea to read manual (User Guide):
http://maven.apache.org/reference/user-guide.html#Test%20Resources

Michal
-----Original Message-----
Sent: Friday, May 30, 2003 7:12 PM
To: Maven Mailing List (E-mail)
Subject: How to add classpath to JUnit Tests
I wish to add additional classpath entries when I run
maven test
because there are additional resources that must be present in
the classpath. For instance
I am generating test cases that test ResourceBundles, so I need
the .properties files in the
classpath. How can I accomplish this?
Thanks, Steve
---------------------------------------------------------------------
----------------------------------------------------------------------
Wizyta Busha w INTERIA.PL >>> http://link.interia.pl/f172d
Steve Garcia
2003-05-30 17:30:14 UTC
Permalink
I have read the user manual, but I have found inconsistencies with it in the past so I'm a little hesistant to completely trust it.

Thanks, Steve

-----Original Message-----
From: Michal Maczka [mailto:***@interia.pl]
Sent: Friday, May 30, 2003 10:29 AM
To: Maven Users List
Subject: RE: How to add classpath to JUnit Tests


It is usually good idea to read manual (User Guide):
http://maven.apache.org/reference/user-guide.html#Test%20Resources

Michal
-----Original Message-----
Sent: Friday, May 30, 2003 7:12 PM
To: Maven Mailing List (E-mail)
Subject: How to add classpath to JUnit Tests
I wish to add additional classpath entries when I run
maven test
because there are additional resources that must be present in
the classpath. For instance
I am generating test cases that test ResourceBundles, so I need
the .properties files in the
classpath. How can I accomplish this?
Thanks, Steve
---------------------------------------------------------------------
----------------------------------------------------------------------
Wizyta Busha w INTERIA.PL >>> http://link.interia.pl/f172d
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@maven.apache.org
For additional commands, e-mail: users-***@maven.apache.org
Steve Garcia
2003-05-30 17:38:49 UTC
Permalink
Although in the case of my previous question I think the manual is straight forward.

On this topic in general, I am confused about some things in the manual. For instance does Maven support the <unitTest> and <unitTestPatterns> elements in the <build> node? I'm playing around with it now to see if there is a difference.

Regards, Steve

-----Original Message-----
From: Steve Garcia
Sent: Friday, May 30, 2003 10:30 AM
To: Maven Users List
Subject: RE: How to add classpath to JUnit Tests


I have read the user manual, but I have found inconsistencies with it in the past so I'm a little hesistant to completely trust it.

Thanks, Steve

-----Original Message-----
From: Michal Maczka [mailto:***@interia.pl]
Sent: Friday, May 30, 2003 10:29 AM
To: Maven Users List
Subject: RE: How to add classpath to JUnit Tests


It is usually good idea to read manual (User Guide):
http://maven.apache.org/reference/user-guide.html#Test%20Resources

Michal
-----Original Message-----
Sent: Friday, May 30, 2003 7:12 PM
To: Maven Mailing List (E-mail)
Subject: How to add classpath to JUnit Tests
I wish to add additional classpath entries when I run
maven test
because there are additional resources that must be present in
the classpath. For instance
I am generating test cases that test ResourceBundles, so I need
the .properties files in the
classpath. How can I accomplish this?
Thanks, Steve
---------------------------------------------------------------------
----------------------------------------------------------------------
Wizyta Busha w INTERIA.PL >>> http://link.interia.pl/f172d
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@maven.apache.org
For additional commands, e-mail: users-***@maven.apache.org


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

Loading...