ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Flemming Haurum <>
Subject RE: JUnit and loading external test data from file
Date Wed, 18 Jun 2003 14:10:30 GMT
Yes I believe you are right if I have one directory with Junit code.
But I have several directories and therefore I am using the
batchtest+filetest and if I should use the sysproperty solution I would need
to set it dynamically, or am I wrong?

It would be fine if I could use something like (pseudo code):

 new FileReader (JUNIT_TEST_DIR + "/testdatafile.txt");

But how to set the JUNIT_TEST_DIR dynamically for each instance found by the

The test data files are located in the same directory as the Junit java
source files.


 -----Original Message-----
From: 	Nicolas Johnson [] 
Sent:	18. juni 2003 15:49
To:	Ant Users List
Subject:	RE: JUnit and loading external test data from file

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:

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