Re: JUnit Test Temp Directory

2003-11-05 Thread Alain Javier Guarnieri del Gesu
* Peter Donald <[EMAIL PROTECTED]> [2003-11-03 22:14]:
> On Tue, 4 Nov 2003 08:59 am, Alain Javier Guarnieri del Gesu wrote:

> > What do you feel is the best place to create temporary files and
> > directories for a unit test?
> >
> > Should I use a directory under target?
> >
> > Should I create a temp file using File.createTempFile()?
> >
> > The latter does not help if I want a temp directory.
> 
> I generally put it under target/test-data. Heres the code I use in
> quite a few of my unit tests to generate base directory for test
> data.

Thank you for the thoughts and the code. That's what I'll do then.

-- 
Alain Javier Guarnieri del Gesu - [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: JUnit Test Temp Directory

2003-11-03 Thread Peter Donald
On Tue, 4 Nov 2003 08:59 am, Alain Javier Guarnieri del Gesu wrote:
> What do you feel is the best place to create temporary files and
> directories for a unit test?
>
> Should I use a directory under target?
>
> Should I create a temp file using File.createTempFile()?
>
> The latter does not help if I want a temp directory.

I generally put it under target/test-data. Heres the code I use in quite a few 
of my unit tests to generate base directory for test data.


private static final File generateDirectory()
throws IOException
{
final File baseDirectory = getBaseDirectory();
final File dir =
File.createTempFile( "mgtest", ".tmp", baseDirectory 
).getCanonicalFile();
dir.delete();
dir.mkdirs();
assertTrue( "dir.exists()", dir.exists() );
return dir;
}

private static final File getBaseDirectory()
{
final String tempDir = System.getProperty( "java.io.tmpdir" );
final String baseDir = System.getProperty( "basedir", tempDir );

final File base = new File( baseDir ).getAbsoluteFile();
final String pathname =
base + File.separator + "target" + File.separator + "test-data";
final File dir = new File( pathname );
dir.mkdirs();
return dir;
}

-- 
Cheers,

Peter Donald
---
 Don't take life too seriously -- 
  you'll never get out of it alive.
---


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



JUnit Test Temp Directory

2003-11-03 Thread Alain Javier Guarnieri del Gesu
What do you feel is the best place to create temporary files and
directories for a unit test?

Should I use a directory under target?

Should I create a temp file using File.createTempFile()? 

The latter does not help if I want a temp directory.

Thoughts, please.

-- 
Alain Javier Guarnieri del Gesu - [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]