Hi,

It probably boils down to either not having the necessary file
('foo.xml') in the Junit classpath or a config problem.
The not-in-classpath problem can be taken care of by specifying the
resource dependency in the 'unitTest' section of the project.xml like
this:

        <unitTest>
            <includes>
                        ...
            </includes>
            <resources>
                <resource>
                    <directory>${basedir}/src/test</directory>
                    <includes>
                        <!-- The 'txt' and 'xml' files are control files
                             for some of the test scenarios.
                          -->
                        <include>**/*.txt</include>
                        <include>**/*.xml</include>
                    </includes>
                </resource>
            </resources>
        </unitTest>

This will instruct Maven to take care of copying all '*.txt' and '*.xml'
files from the '${basedir}/src/test' into the 'classes-test' folder and
thus in your Junit classpath.

The file should then be found using the 'getSystemResourceAsStream()'
method (since it reads from the classpath).


The second possibility is configuration. I also had some problems
locating files in Junit tests because of forking issues. If the above
does not help, try creating a 'project.properties' file next to your
'project.xml' file and include this:

        # Forked JUnit because of some problems involving classloading
of resources in test scenarios.
        maven.junit.fork=true


Hope this helps.

lnnrt. 
---
"Do not seek to follow in the footsteps of the men of old; seek what
they sought."
   --Basho

 
Lennart Martens
 
public key (http://genesis.ugent.be/lmPGPkey)
 
www.proteomics.be
Dept. Medical Protein Research (VIB09)
Flanders Interuniversity Institute for Biotechnology
Faculty of Medicine and Health Sciences
Ghent University
 
Rommelaere Institute - Building D
A. Baertsoenkaai 3
B-9000 Ghent
Belgium
 
Tel.:+32-(0)9 264 93 59
Fax: +32-(0)9 264 94 84



-----Original Message-----
From: Ciaran Treanor [mailto:[EMAIL PROTECTED] 
Sent: vrijdag 5 december 2003 9:08
To: Maven Users List
Subject: JUnit and getResourceAsStream


I've got a unit test that needs to read a data file, i.e. InputStream in
= getClass().getResourceAsStream("foo.xml");

Within Eclipse the file is found, however when running the
test from within Maven the resource is not found (i.e. in is null).

Any ideas?

ct



---------------------------------------------------------------------
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