Hi,

trying to answer your questions one after the other:

1. Your original question (How to ensure your testdata directory gets
   copied to test-classes):

By default maven expects resources for unit testing that should end up in the classpath in src/test/resources. If you have resources in other directories you must declare them as an additional resources:

  <project>
   [...]
   <build>
     [...]
     <testResources>
       <testResource>
         <directory> [your folder here] </directory>
       </testResource>
     </testResources>
     [...]
   </build>
   [...]
  </project>

Read more about this in the pom description [1] and the description of the resource plugin [2].

2. Accessing your resources via the filesystem:

It is considered bad style to access resources on the classpath as file objects (think about resources in jar files). You really should use *.getResourceAsStream(*) for accessing such resources.

If you really have to go the way of accessing your testdata via the filesystem (File objects) there is no need to have them on the classpath (read: add them as resources to your pom). Instead just access them from
their filesystem location (src/test/testdata).

Your example from one of your other mails:

  File("abc.doc").exists()

just can not work, since you are trying to access the file via a relative location, assuming the file is in your current working directory, which is not the case. The default working directory should be your projects root directory, if I remember correctly.

Instead you should access your files via an absolute location. This is what Deng pointed you to with the PlexusTestCase [3]. It's the base TestCase used by plexus for all its unit tests. It provides a utility method to retrieve the absolute path of your projects root directory (getBaseDir()). You can easily adapt this utility method from Plexus to your own TestCases and the create File objects in the way Deng suggested:

  File( getBasedir(), "/target/test-classes/abc.doc" )

Hope this helps
-Tim

[1] http://maven.apache.org/pom.html
[2] http://maven.apache.org/plugins/maven-resources-plugin/index.html
[3] https://svn.codehaus.org/plexus/plexus-containers/trunk/plexus-container-default/src/main/java/org/codehaus/plexus/PlexusTestCase.java

Karthik Krishnan schrieb:
Hi Deng,

I have no idea what you are talking about. I have looked at the plexus, but
I am sorry to say that i did not understood the question. I am using TestNG
to unit test components.

Thanks,

Kartik

On Fri, May 9, 2008 at 9:14 PM, Maria Odea Ching <[EMAIL PROTECTED]> wrote:

try new File( getBasedir(), "/target/test-classes/abc.doc" ) assuming
you're
extending the PlexusTestCase :-)

-Deng

On Fri, May 9, 2008 at 3:58 AM, krishnan.1000 <[EMAIL PROTECTED]>
 wrote:

Hi,

I have tried moving them to src/test/resources, but I have found that if
I
have to create a file object of a file say abc.doc, present under
src/test/resources,  then new File("abc.doc").exists() returns false
always,
but the ClassLoader.getSystemResourceAsStream("abc.doc") != null returns
true. I need access to the file object.

Maria Odea Ching-5 wrote:
You might need to write code in your unit tests for copying your test
resources from src/test/testdata to target/test-classes as I don't
think
you
could set this in the plugin config.
The other alternative is to move your test resources to
src/test/resources
so that it automatically gets copied in target/test-classes but you
mentioned changing the structure is not an option for you..

HTH,
Deng

On Thu, May 8, 2008 at 2:24 PM, krishnan.1000 <[EMAIL PROTECTED]
wrote:

Hi,

I have a project that uses a set of sample data for unittesting on
the
project. Since there are many other developer on the project, this
would
help them simulate the same working environment.

The test folders are in the project root- src/test/testdata/abc.doc
and
so
on...  This has been a standard practise in my company.

However, when I run mvn test, I see that this folder is not copied
under
the
target/test-classes folder.  Is there a way to make sure that this
folder
is
copied. Keeping the same folder structure.

Thanks,

Karthik Krishnan
--
View this message in context:
http://www.nabble.com/mvn-add-test-folders-tp17120968p17120968.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
View this message in context:
http://www.nabble.com/mvn-add-test-folders-tp17120968p17135234.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to