You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Webb Morris <we...@yahoo.com> on 2004/06/17 21:39:04 UTC
junit tests and resources
I have set up some resources for my unit tests in the unittest/resources area of my project.xml.
These resources are being correctly copied to the target/test-classes directory. However, when I
try to access these resources using:
ClassLoader.getSystemResourceAsStream(myresource)
The resource can not be found.
Any ideas?
WM
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: junit tests and resources
Posted by Brett Porter <br...@gmail.com>.
SomeTest.class.getResourceAsStream (or
getClass().getResourceAsStream()) would work just as effectively. This
is how I would do it whether I was using Maven or not.
This is not a "weird thing" - Maven doesn't shove everything onto the
system classloader, it builds up its own.
- Brett
On Fri, 18 Jun 2004 11:49:13 -0700 (PDT), Webb Morris
<we...@yahoo.com> wrote:
>
> In case anyone is following this thread or finds it while solving their own problem in the future,
> here is what I ended up having to do:
>
> InputStream is =
> Thread.currentThread().getContextClassLoader()
> .getResourceAsStream(testResource);
>
> Apparently there are some weird things going on with the JUnit ClassLoader. Also, if you are
> attempting to access a resource in the root directory (directly under test-classes) then be sure
> to prefix your resource with a "/" (i.e. "/text.xml").
>
> Thanks to those who tried to help!
>
> WM
>
>
>
> --- Webb Morris <we...@yahoo.com> wrote:
> > Yes, the call simply returns null. It really doesn't make much sense. When I run maven with the
> > -X option I can see the path being included, but when I try to access the resource, I get null.
> >
> > WM
> >
> > --- Dion Gillard <di...@gmail.com> wrote:
> > > The resources aren't on the system classloader?
> > >
> > > On Thu, 17 Jun 2004 12:39:04 -0700 (PDT), Webb Morris
> > > <we...@yahoo.com> wrote:
> > > >
> > > > I have set up some resources for my unit tests in the unittest/resources area of my
> > > project.xml.
> > > > These resources are being correctly copied to the target/test-classes directory. However,
> > when
> > > I
> > > > try to access these resources using:
> > > >
> > > > ClassLoader.getSystemResourceAsStream(myresource)
> > > >
> > > > The resource can not be found.
> > > >
> > > > Any ideas?
> > > >
> > > > WM
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> > > > Yahoo! Mail - You care about security. So do we.
> > > > http://promotions.yahoo.com/new_mail
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > > For additional commands, e-mail: users-help@maven.apache.org
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > >
> > >
> >
> >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Take Yahoo! Mail with you! Get it on your mobile phone.
> > http://mobile.yahoo.com/maildemo
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - You care about security. So do we.
> http://promotions.yahoo.com/new_mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: junit tests and resources
Posted by Webb Morris <we...@yahoo.com>.
In case anyone is following this thread or finds it while solving their own problem in the future,
here is what I ended up having to do:
InputStream is =
Thread.currentThread().getContextClassLoader()
.getResourceAsStream(testResource);
Apparently there are some weird things going on with the JUnit ClassLoader. Also, if you are
attempting to access a resource in the root directory (directly under test-classes) then be sure
to prefix your resource with a "/" (i.e. "/text.xml").
Thanks to those who tried to help!
WM
--- Webb Morris <we...@yahoo.com> wrote:
> Yes, the call simply returns null. It really doesn't make much sense. When I run maven with the
> -X option I can see the path being included, but when I try to access the resource, I get null.
>
> WM
>
> --- Dion Gillard <di...@gmail.com> wrote:
> > The resources aren't on the system classloader?
> >
> > On Thu, 17 Jun 2004 12:39:04 -0700 (PDT), Webb Morris
> > <we...@yahoo.com> wrote:
> > >
> > > I have set up some resources for my unit tests in the unittest/resources area of my
> > project.xml.
> > > These resources are being correctly copied to the target/test-classes directory. However,
> when
> > I
> > > try to access these resources using:
> > >
> > > ClassLoader.getSystemResourceAsStream(myresource)
> > >
> > > The resource can not be found.
> > >
> > > Any ideas?
> > >
> > > WM
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Yahoo! Mail - You care about security. So do we.
> > > http://promotions.yahoo.com/new_mail
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Take Yahoo! Mail with you! Get it on your mobile phone.
> http://mobile.yahoo.com/maildemo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: junit tests and resources
Posted by Webb Morris <we...@yahoo.com>.
Yes, the call simply returns null. It really doesn't make much sense. When I run maven with the
-X option I can see the path being included, but when I try to access the resource, I get null.
WM
--- Dion Gillard <di...@gmail.com> wrote:
> The resources aren't on the system classloader?
>
> On Thu, 17 Jun 2004 12:39:04 -0700 (PDT), Webb Morris
> <we...@yahoo.com> wrote:
> >
> > I have set up some resources for my unit tests in the unittest/resources area of my
> project.xml.
> > These resources are being correctly copied to the target/test-classes directory. However, when
> I
> > try to access these resources using:
> >
> > ClassLoader.getSystemResourceAsStream(myresource)
> >
> > The resource can not be found.
> >
> > Any ideas?
> >
> > WM
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Mail - You care about security. So do we.
> > http://promotions.yahoo.com/new_mail
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: junit tests and resources
Posted by Dion Gillard <di...@gmail.com>.
The resources aren't on the system classloader?
On Thu, 17 Jun 2004 12:39:04 -0700 (PDT), Webb Morris
<we...@yahoo.com> wrote:
>
> I have set up some resources for my unit tests in the unittest/resources area of my project.xml.
> These resources are being correctly copied to the target/test-classes directory. However, when I
> try to access these resources using:
>
> ClassLoader.getSystemResourceAsStream(myresource)
>
> The resource can not be found.
>
> Any ideas?
>
> WM
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - You care about security. So do we.
> http://promotions.yahoo.com/new_mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org