You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by tarjei <ta...@nu.no> on 2008/02/24 14:43:53 UTC
Setting up relative testpaths
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi, I got a test that needs to read a file in src/test/resources. How
should I write the test to get the information about the relative path
to that file, either using TestNG or just plain Junit?
Kind regards,
Tarjei
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHwXSZYVRKCnSvzfIRApi3AJ9BqL+U4acMHTDeOjwnqP9/jru/OQCfYXqJ
hE4f1vgaeBVWkww/ngZ5KFM=
=kkm7
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Setting up relative testpaths
Posted by tarjei <ta...@nu.no>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
simon wrote:
> On Sun, 2008-02-24 at 14:43 +0100, tarjei wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi, I got a test that needs to read a file in src/test/resources. How
>> should I write the test to get the information about the relative path
>> to that file, either using TestNG or just plain Junit?
>
> It's best to avoid files at all. Where possible, I suggest using
> Class.getResourceAsStream(...)
> to access the data you want. The stuff in src/test/resources is on the
> classpath.
>
> If you really need a File object, then try
> URL url = Class.getResource(...);
> File f = url.tgetFile()
>
Thanks, that nailed it.
Tarjei
> Regards,
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHwZPkYVRKCnSvzfIRAnGUAKCvNN6olUYXmpnkN8ijPjMO29cT/gCcDDkr
vxApKdlxKGixGolmnGYTC60=
=SNoo
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Setting up relative testpaths
Posted by simon <si...@chello.at>.
On Sun, 2008-02-24 at 14:43 +0100, tarjei wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi, I got a test that needs to read a file in src/test/resources. How
> should I write the test to get the information about the relative path
> to that file, either using TestNG or just plain Junit?
It's best to avoid files at all. Where possible, I suggest using
Class.getResourceAsStream(...)
to access the data you want. The stuff in src/test/resources is on the
classpath.
If you really need a File object, then try
URL url = Class.getResource(...);
File f = url.tgetFile()
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Setting up relative testpaths
Posted by simon <si...@chello.at>.
On Sun, 2008-02-24 at 16:09 +0100, Jan Torben Heuer wrote:
> tarjei wrote:
>
> > Hi, I got a test that needs to read a file in src/test/resources. How
> > should I write the test to get the information about the relative path
> > to that file, either using TestNG or just plain Junit?
>
> I got unpredictable results when using test-resources and maven: eclipse
> (junit plugin) and mvn test both ran successfully the test but mvn install
> or mvn tomcat:deploy failed.
>
> Avoid test-resources if possible.
Well, I use it extensively in half-a-dozen different projects and have
no such problems...
Regards, Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Setting up relative testpaths
Posted by Jan Torben Heuer <jt...@mail2003.dnsalias.org>.
tarjei wrote:
> Hi, I got a test that needs to read a file in src/test/resources. How
> should I write the test to get the information about the relative path
> to that file, either using TestNG or just plain Junit?
I got unpredictable results when using test-resources and maven: eclipse
(junit plugin) and mvn test both ran successfully the test but mvn install
or mvn tomcat:deploy failed.
Avoid test-resources if possible.
Jan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org