Unit Test requires access to a file.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Unit Test requires access to a file.

vachevil-basic
Hello

I am a Maven novice and have a question about Unit Test.

My Unit Test requires access to a file (for testing reading/parsing).  
Where should I put this file?
how can it be transferred in the right place in target? (I have not found any equivalent to the
<resources> tag for unit tests (I do not want the files to be added to the jar).

Also how should I access it?  I could "attach" it to the Test class and use the ResourceStream
butthen the question is how to copy the xml file to the test-classes directories
    parser.parse(new InputSource(new FileInputStream("good-file.xml")));

I am sure that it must be trivial... but I have no idea.

Any suggestion most welcomed!

Kind regards

Benoit

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Unit Test requires access to a file.

Wim Deblauwe
http://maven.apache.org/reference/project-descriptor.html#unitTest_resources

The best way to access resources in java:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String)
You just have to make sure your resouce is in a directory that is on
the classpath

regards,

Wim

2005/5/29, [hidden email] <[hidden email]>:

> Hello
>
> I am a Maven novice and have a question about Unit Test.
>
> My Unit Test requires access to a file (for testing reading/parsing).
> Where should I put this file?
> how can it be transferred in the right place in target? (I have not found any equivalent to the
> <resources> tag for unit tests (I do not want the files to be added to the jar).
>
> Also how should I access it?  I could "attach" it to the Test class and use the ResourceStream
> butthen the question is how to copy the xml file to the test-classes directories
>     parser.parse(new InputSource(new FileInputStream("good-file.xml")));
>
> I am sure that it must be trivial... but I have no idea.
>
> Any suggestion most welcomed!
>
> Kind regards
>
> Benoit
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Unit Test requires access to a file.

Alex Soto
In reply to this post by vachevil-basic
place a <resources> section in your <unitTest> section.
http://maven.apache.org/reference/project-descriptor.html#unitTest_resources


On 5/29/05, [hidden email] <[hidden email]> wrote:

>
> Hello
>
> I am a Maven novice and have a question about Unit Test.
>
> My Unit Test requires access to a file (for testing reading/parsing).
> Where should I put this file?
> how can it be transferred in the right place in target? (I have not found
> any equivalent to the
> <resources> tag for unit tests (I do not want the files to be added to the
> jar).
>
> Also how should I access it? I could "attach" it to the Test class and use
> the ResourceStream
> butthen the question is how to copy the xml file to the test-classes
> directories
> parser.parse(new InputSource(new FileInputStream("good-file.xml")));
>
> I am sure that it must be trivial... but I have no idea.
>
> Any suggestion most welcomed!
>
> Kind regards
>
> Benoit
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>