ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicolas Johnson" <>
Subject RE: JUnit and loading external test data from file
Date Wed, 18 Jun 2003 13:48:38 GMT
You might try an alternative solution.  When I use external files in my Test
classes I get the file name from a property.   I set the property in a
forked jvm instance that is used when running JUnit.  Something like:

<junit fork="yes" haltonfailure="yes">
    <sysproperty key="test.path" value="${test_docs}"/>



that way I can easily change the path to the test files without having to
recompile the sourcecode.

-----Original Message-----
From: Flemming Haurum []
Sent: Wednesday, June 18, 2003 4:58 AM
To: ''
Subject: JUnit and loading external test data from file

I have a problem with Junit test code that needs to load external test data
from files.

My test code opens the test data file the following way:
try {
FileReader fileReader = new FileReader("testdatafile.txt");

            bufferedReader = new BufferedReader(fileReader);

        } catch (FileNotFoundException e) {
            assertTrue("Run the unit test from within the test
directory!!!!" +
                       e.getMessage(), false);
        } catch (IOException e) {
            assertTrue(e.getMessage(), false);

It works when I am running the Junit from the directory where the test code
and the test files are located. ant -find build.xml junit
But when I run the Junit from a higher level in the directory structure it
fails as the test data file is specified by name without path. I would hate
if I have to use absolute file reference as

My build.xml contains the following regarding the junit.

    <junit printsummary="yes" haltonfailure="no">
        <classpath refid="component.testClasspath"/>

        <formatter type="xml" />

        <!-- JUnit has its own class loader that cannot handle the multiple
        classes found in our class path. Therefore it is necessary with a
        seperate VM for the unit tests.  -->
        <batchtest fork="yes" todir="${build.junitReport}">
            <fileset dir="${build.testsrc}">
                <include name="**/*" />
                <exclude name="**/" />

Should I use the 'dir' attribute to specify that the VM should be invoked in
a different directoy? And in that case how to write the statement as I am
using the batchtest+fileset to find directories containing the Junit test

Do some of you have experience or advise on how to load the test data files.

Regards Flemming

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message