Just a short note tho:

There is no system property called java.io.tmp.dir

it's called java.io.tmpdir

Kind regards,
Dave Sag




 


David Sag <[EMAIL PROTECTED]> wrote on 18-11-2005 11:08:17:

>
> Thanks John those answers were perfectly satisfactory and i have
> updated my code accordingly.
>
> a point to note however - the path to the resource should not start witha '/'
>
> i have not looked but i wonder what the file path to a file within a
> jar looks like.  under maven the unit tests run before the jar is
> made.  i shall explore this a bit more.
>
> and two - i went with the java.io.tmp.dir idea - seemed to me to be
> the most useful.
>
> Kind regards,
> Dave Sag
>
>
> [image removed]
>
>  
>
> John Casey <[EMAIL PROTECTED]> wrote on 17-11-2005 16:52:13:
>
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > David Sag wrote:
> > |
> > | I am writing the unit tests for a simple xml transformer and want to
> > | know 2 things.
> > |
> > | 1) where is the maven2 approved place to put the test xml and xslt
> > | files?  If I put them in src/test/resources then they end up in a jar
> > | file, and I am not sure how i refer to their path when i invoke File xml
> > | = new File("test.xm;");
> > |   - so advice wanted please.
> >
> > it may be a little hacky, but what I've used is:
> >
> > ClassLoader loader = getClass().getClassLoader();
> > String resourceName = "/path/to/test.xslt";
> > URL resource = loader.getResource( resourceName );
> >
> > File testFile;
> > if ( resource != null )
> > {
> > ~    testFile = new File( resource.getPath() );
> > }
> > else
> > {
> > ~    throw new SomethingException(..);
> > }
> >
> > // use file.
> >
> > This assumes that the test resources are somewhere in the classpath, not
> > necessarily in a jar. It works regardless of the ${user.dir} used, which
> > ~  makes it more resilient to IDE vs. Maven test invocation...
> >
> > |
> > | 2) where is the best place to write test output that I then clean up?
> > |  in this case i want to write out the transformed file and check that it
> > | contains what I expect.  I am wtiting to target/temp - is that what you
> > | other maven2  users are doing?
> >
> > You could pass in the directory via:
> >
> > <build>
> > ~  ...
> > ~  <plugins>
> > ~    <plugin>
> > ~      <artifactId>maven-surefire-plugin</artifactId>
> >
> > ~      <configuration>
> > ~        <systemProperties>
> > ~          <output>${project.build.directory}/temp</output>
> > ~        </systemProperties>
> > ~      </configuration>
> > ~    </plugin>
> > ~  </plugins>
> > </build>
> >
> > This is usually going to be the same as using target/temp, but it will
> > track any changes in <build><directory/></build> within the POM. Of
> > course, that means you'll have to call:
> >
> > System.setProperty( "output", "/path" );
> >
> > when you want to run the test outside of Maven...Another possibility
> > would be to use a location within ${java.io.tmp.dir}...a temporaryfile/dir.
> >
> > HTH,
> >
> > John
> >
> > |
> > | Kind regards,
> > | Dave Sag
> > |
> > |
> > |
> > |
> > |
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.2.6 (GNU/Linux)
> >
> > iD8DBQFDfKctK3h2CZwO/4URApFTAJsFhDlZaD5y1eO5UXWIfPkpQkRq+ACcCHcX
> > 5TlKSnWBjnCF7y/8J0f/Z/k=
> > =0ZHf
> > -----END PGP SIGNATURE-----
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >

Reply via email to