ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Flemming Haurum <>
Subject JUnit and loading external test data from file
Date Wed, 18 Jun 2003 09:58:03 GMT
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

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message