You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Keith Irwin <ke...@keithirwin.com> on 2004/01/02 06:42:39 UTC
Re: What is the proper way to handle resource bundles when unit
testing?
On Thu, 2004-01-01 at 20:47, Chad Woolley wrote:
> Hi,
>
> I use a resource bundle in my app. In my ResourceManager class, I load it like
> this:
>
> ClassLoader classLoader = this.getClass().getClassLoader();
> resourceBundle = ResourceBundle.getBundle(resourceFileName, locale,
> classLoader);
Hm. I used cactus tests to run unit tests in a container to get this
working. I'm guessing that it won't work unless your resource bundles
are on the classpath. How you add *.properties files to a classpath in
Maven -- well, I don't know. ;)
I'm curious, but does the <resource> tag take care of this? Or do you
have to do something interesting in maven.xml?
Keith
> However, when I run my ResourceManagerTest unit test via the default "test"
> goal, my class always fails because it cannot find the resource bundle.
>
> I tried specifying the bundle in the <resources> section of project.xml, but
> this doesn't seem to work.
>
> Is there a standard way to handle this, or any other maven projects that I can
> look at for an example?
>
> FYI - if I make custom goals to manually copy the bundle to basedir, and
> manually invoke JUnit, then it works. This method doesn't work when using the
> standard maven "test" goal, though.
>
> Thanks,
> Chad
>
>
>
> ---------------------------------------------------------------------
> 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: What is the proper way to handle resource bundles when unit testing?
Posted by di...@multitask.com.au.
Yes, you use <resources> for this.
e.g.
<build>
.....
<resources>
<resource>
<directory>src/conf</directory>
<includes>
<include>*.xsd</include>
<include>*.dtd</include>
<include>*.mod</include>
<include>*.properties</include>
<include>driver.jelly</include>
</includes>
</resource>
<resource>
<directory>src/messages</directory>
<targetPath>org/apache/maven/messages</targetPath>
<includes>
<include>messages*.properties</include>
</includes>
</resource>
</resources>
</build>
--
dIon Gillard, Multitask Consulting
Blog: http://blogs.codehaus.org/people/dion/
Keith Irwin <ke...@keithirwin.com> wrote on 02/01/2004 04:42:39 PM:
> On Thu, 2004-01-01 at 20:47, Chad Woolley wrote:
> > Hi,
> >
> > I use a resource bundle in my app. In my ResourceManager class, I
load it like
> > this:
> >
> > ClassLoader classLoader = this.getClass().getClassLoader();
> > resourceBundle = ResourceBundle.getBundle(resourceFileName,
locale,
> > classLoader);
>
> Hm. I used cactus tests to run unit tests in a container to get this
> working. I'm guessing that it won't work unless your resource bundles
> are on the classpath. How you add *.properties files to a classpath in
> Maven -- well, I don't know. ;)
>
> I'm curious, but does the <resource> tag take care of this? Or do you
> have to do something interesting in maven.xml?
>
> Keith
>
> > However, when I run my ResourceManagerTest unit test via the default
"test"
> > goal, my class always fails because it cannot find the resource
bundle.
> >
> > I tried specifying the bundle in the <resources> section of
project.xml, but
> > this doesn't seem to work.
> >
> > Is there a standard way to handle this, or any other maven projects
that I can
> > look at for an example?
> >
> > FYI - if I make custom goals to manually copy the bundle to basedir,
and
> > manually invoke JUnit, then it works. This method doesn't work when
using the
> > standard maven "test" goal, though.
> >
> > Thanks,
> > Chad
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org