I am working on a web application with JUnit 3 tests.  We have resources
which are different for running within the application (within the
container) and within JUnit tests (outside the container).  An example
is persistence.xml (the configuration file for Hibernate Entity
Manager).  The production version (residing in
src/main/resources/META-INF) specifies a DataSource to be accessed
through JNDI, while the test version (src/test/resources/META-INF)
specifies a straight JDBC connection (since it cannot be assumed that a
container is available).

However, when I run the "package" goal, which runs the unit tests before
creating the WAR file, I can see that both versions of the file make it
into the "target" directory, one under "classes" and one under
"test-classes".  The problem is that during execution of the JUnit
tests, the version of the file under "classes" (intended for execution
within a container) appears to get picked up first (the JUnit tests
complain that the DataSource is unavailable and fail).

I had assumed that the point of having the "main" and "test" directories
was to be able to specify different versions of resources for unit
testing and running as an application.  Is this not a valid assumption,
or am I doing something else wrong?

Thanks,
Dhruva B. Reddy
Senior Associate of Technology, Level 2 | Sapient

25 1st Street
Cambridge, MA, 02141, USA
desk: +1 617 452 1900
fax: +1 617 621 1300

www.sapient.com

Reply via email to