commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: [math] stupid question about test input files
Date Wed, 14 May 2003 23:49:35 GMT


On Wed, 14 May 2003, Phil Steitz wrote:

> Date: Wed, 14 May 2003 14:10:26 -0700 (PDT)
> From: Phil Steitz <steitzp@yahoo.com>
> Reply-To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> To: commons-dev@jakarta.apache.org
> Subject: RE: [math] stupid question about test input files
>
> Sorry if I am being exceedingly dense here, but I
> looked at the Digester test cases and unless I am
> missing something, that approach will not work for me,
> since the objects that I am testing open files
> themselves using fully qualified file paths passed in
> to them as strings -- i.e., my test cases have code
> like:
>
> empiricalDistribution.setFilePath("full-file-path");
> or empiricalDistribution.load("full-file-path");
>
> In my local non-jakarta-standard setup, I use the ant
> java dir attribute to force the tests to run from the
> location where the test data file lives or I use full
> path specs.  I do not like this.  Am I missing some
> easy way out of this ugliness?
>
> If the answer is to extend the API to take Files or
> Streams, I am or course open to this, but I would
> prefer to do so for a reason other than so that I can
> get my tests deployed :-)
>

If you *really* need disk files, I'd suggest using a relative path from
the default directory.  For example, if you had a "src/test/resources"
directory in the repository, with a "foo.txt" file in it, the relative
path would be:

  src/test/resources/foo.txt

and this would work no matter where the developer actually had the
repository in their own workspace -- and also works portably across
platforms courtesy of Java's handling of slashes for you.

If you need absolute paths, you can still get one of those as well:

  File dir = new File(".");
  File file = new File(dir, "src/test/resources/foo.txt");
  String path = file.getAbsolutePath();

without having to hard code anything.

> Phil

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message