You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jose Gonzalez Gomez <jg...@gmail.com> on 2006/07/11 13:53:22 UTC

Best practices in testing Hibernate/EJB3 POJOs (or doing database tests)

Hi there,

I would like to hear about what you're doing to test your Hibernate/EJB3
POJOs (if you're doing at all). I have a project with some of them, and I
have the following concerns:

First of all, I may test them just ignoring persistence (already done). No
problem here, just a bunch of TestNG tests running smoothly under Maven2. I
think this is important, as I'm developing a library mainly intended to be
used as annotated Hibernated POJOs, but maybe people using it prefer another
persistence api. What do you think?

Then I thought about testing the library including the persistence stuff,
but this brings some problems:

Problem 1: Whenver building the project, publishing the site, etc. you must
have access to a runnning database in order to perform the tests. I'm
currently running a postgresql database, but it may be cumbersome for users
wanting to download and hack the sources. Maybe this could be solved using
some kind of embeddable database? Or maybe I could create several profiles
(never done this) and activate database tests only under demand?

Problem 2: Having database tests involves having configuration data written
down in some configuration file (the jdbc URL, user, password, etc.
hibernate.cfg.xml) or even in the pom (jdbc driver dependency). It's kind of
putting in the sources of the library some information that may be only of
interest to me in my current environment. How to solve this? Again using
some kind of embeddable datasource for tests? Using source filters? (again,
I haven't done this before, so I don't know if it's suitable)

Best regards
Jose

Re: Best practices in testing Hibernate/EJB3 POJOs (or doing database tests)

Posted by Simone Gianni <s....@thebug.it>.
Hi Jose,
we usually use hypersonic DB, which is a very lightweight, embeddable
DB, able to run in "ram only" mode. You can simply set it up in the test
setup method and shut it down in the teardown.

http://www.hsqldb.org/

Hope this helps,
Simone

Jose Gonzalez Gomez wrote:

> Hi there,
>
> I would like to hear about what you're doing to test your Hibernate/EJB3
> POJOs (if you're doing at all). I have a project with some of them, and I
> have the following concerns:
>
> First of all, I may test them just ignoring persistence (already
> done). No
> problem here, just a bunch of TestNG tests running smoothly under
> Maven2. I
> think this is important, as I'm developing a library mainly intended
> to be
> used as annotated Hibernated POJOs, but maybe people using it prefer
> another
> persistence api. What do you think?
>
> Then I thought about testing the library including the persistence stuff,
> but this brings some problems:
>
> Problem 1: Whenver building the project, publishing the site, etc. you
> must
> have access to a runnning database in order to perform the tests. I'm
> currently running a postgresql database, but it may be cumbersome for
> users
> wanting to download and hack the sources. Maybe this could be solved
> using
> some kind of embeddable database? Or maybe I could create several
> profiles
> (never done this) and activate database tests only under demand?
>
> Problem 2: Having database tests involves having configuration data
> written
> down in some configuration file (the jdbc URL, user, password, etc.
> hibernate.cfg.xml) or even in the pom (jdbc driver dependency). It's
> kind of
> putting in the sources of the library some information that may be
> only of
> interest to me in my current environment. How to solve this? Again using
> some kind of embeddable datasource for tests? Using source filters?
> (again,
> I haven't done this before, so I don't know if it's suitable)
>
> Best regards
> Jose
>
-- 
Simone Gianni

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Best practices in testing Hibernate/EJB3 POJOs (or doing database tests)

Posted by Alexandre Touret <at...@free.fr>.
Hello
Jose Gonzalez Gomez wrote:
> Problem 1: Whenver building the project, publishing the site, etc. you 
> must
> have access to a runnning database in order to perform the tests. I'm
> currently running a postgresql database, but it may be cumbersome for 
> users
> wanting to download and hack the sources. Maybe this could be solved 
> using
> some kind of embeddable database? Or maybe I could create several 
> profiles
> (never done this) and activate database tests only under demand?
>
In my company we have choosen to create a dedicated schema for running 
junit tests nightly. It s easier to configure and more secure for data 
integrity. In my opinion, you should use several profiles and add one 
for run tests
> Problem 2: Having database tests involves having configuration data 
> written
> down in some configuration file (the jdbc URL, user, password, etc.
> hibernate.cfg.xml) or even in the pom (jdbc driver dependency). 
With both maven 1 and maven 2 you can separate clearly the test  
configuration of the runtime.
> It's kind of
> putting in the sources of the library some information that may be 
> only of
> interest to me in my current environment. How to solve this? 
I think you sould use a tool which produce some injections of 
dependencies like spring. It will be easier for you.

Hope this helps
Regards,
Alexandre Touret

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Best practices in testing Hibernate/EJB3 POJOs (or doing database tests)

Posted by Chris Richardson <ch...@gmail.com>.
Jose,

Here are a couple of things you might find interesting:
* A excerpt from my book POJOs in Action on testing a persistence
layer: http://www.theserverside.com/tt/articles/article.tss?l=PersistentDomain
* The slide from my JavaOne talk on the same topic:
http://www.chrisrichardson.net/presentations/JavaOne2006Testing_dist.ppt

The tests that access the database use a Spring application context
that points to the test DB, which is typically HSQLDB.

With regards to using annotated Hibernated POJOs:. there is a good
case to be made that annotated POJOs are not POJOs (see
http://www.aspectprogrammer.org/blogs/adrian/2004/08/when_is_a_pojo.html).
In the case of a library using XML configuration might enable
different persistence mechanisms to be used.

Chris

-- 
Enterprise POJO consulting - http://www.chrisrichardson.net
Author, POJOs in Action - http://www.manning.com/crichardson
Enterprise POJOs blog - http://chris-richardson.blog-city.com



On 7/11/06, Jose Gonzalez Gomez <jg...@gmail.com> wrote:
> Hi there,
>
> I would like to hear about what you're doing to test your Hibernate/EJB3
> POJOs (if you're doing at all). I have a project with some of them, and I
> have the following concerns:
>
> First of all, I may test them just ignoring persistence (already done). No
> problem here, just a bunch of TestNG tests running smoothly under Maven2. I
> think this is important, as I'm developing a library mainly intended to be
> used as annotated Hibernated POJOs, but maybe people using it prefer another
> persistence api. What do you think?
>
> Then I thought about testing the library including the persistence stuff,
> but this brings some problems:
>
> Problem 1: Whenver building the project, publishing the site, etc. you must
> have access to a runnning database in order to perform the tests. I'm
> currently running a postgresql database, but it may be cumbersome for users
> wanting to download and hack the sources. Maybe this could be solved using
> some kind of embeddable database? Or maybe I could create several profiles
> (never done this) and activate database tests only under demand?
>
> Problem 2: Having database tests involves having configuration data written
> down in some configuration file (the jdbc URL, user, password, etc.
> hibernate.cfg.xml) or even in the pom (jdbc driver dependency). It's kind of
> putting in the sources of the library some information that may be only of
> interest to me in my current environment. How to solve this? Again using
> some kind of embeddable datasource for tests? Using source filters? (again,
> I haven't done this before, so I don't know if it's suitable)
>
> Best regards
> Jose
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Best practices in testing Hibernate/EJB3 POJOs (or doing database tests)

Posted by An...@ubs.com.
Have you thought about using dependency injection framework to cater for
this ?

A 

-----Original Message-----
From: Jose Gonzalez Gomez [mailto:jgonzalez.openinput@gmail.com] 
Sent: 11 July 2006 12:53
To: Maven Users List
Subject: Best practices in testing Hibernate/EJB3 POJOs (or doing
database tests)

Hi there,

I would like to hear about what you're doing to test your Hibernate/EJB3
POJOs (if you're doing at all). I have a project with some of them, and
I have the following concerns:

First of all, I may test them just ignoring persistence (already done).
No problem here, just a bunch of TestNG tests running smoothly under
Maven2. I think this is important, as I'm developing a library mainly
intended to be used as annotated Hibernated POJOs, but maybe people
using it prefer another persistence api. What do you think?

Then I thought about testing the library including the persistence
stuff, but this brings some problems:

Problem 1: Whenver building the project, publishing the site, etc. you
must have access to a runnning database in order to perform the tests.
I'm currently running a postgresql database, but it may be cumbersome
for users wanting to download and hack the sources. Maybe this could be
solved using some kind of embeddable database? Or maybe I could create
several profiles (never done this) and activate database tests only
under demand?

Problem 2: Having database tests involves having configuration data
written down in some configuration file (the jdbc URL, user, password,
etc.
hibernate.cfg.xml) or even in the pom (jdbc driver dependency). It's
kind of putting in the sources of the library some information that may
be only of interest to me in my current environment. How to solve this?
Again using some kind of embeddable datasource for tests? Using source
filters? (again, I haven't done this before, so I don't know if it's
suitable)

Best regards
Jose

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Best practices in testing Hibernate/EJB3 POJOs (or doing database tests)

Posted by Johann Reyes <jr...@hiberforum.org>.
Hello Jose

About problem 1: You can use HSQL

About problem 2: You can run the tests against HSQL, so you can the
connection properties inside your test directory, so those tests would just
run against your embeddable database. An example can be found here:

http://fisheye.codehaus.org/browse/mojo/trunk/mojo/mojo-sandbox/hibernate3-m
aven-plugin/src/test/project-jdk15/src/main/resources/database.properties?r=
1673

Regards

Johann Reyes

-----Original Message-----
From: Jose Gonzalez Gomez [mailto:jgonzalez.openinput@gmail.com] 
Sent: Tuesday, July 11, 2006 7:53 AM
To: Maven Users List
Subject: Best practices in testing Hibernate/EJB3 POJOs (or doing database
tests)

Hi there,

I would like to hear about what you're doing to test your Hibernate/EJB3
POJOs (if you're doing at all). I have a project with some of them, and I
have the following concerns:

First of all, I may test them just ignoring persistence (already done). No
problem here, just a bunch of TestNG tests running smoothly under Maven2. I
think this is important, as I'm developing a library mainly intended to be
used as annotated Hibernated POJOs, but maybe people using it prefer another
persistence api. What do you think?

Then I thought about testing the library including the persistence stuff,
but this brings some problems:

Problem 1: Whenver building the project, publishing the site, etc. you must
have access to a runnning database in order to perform the tests. I'm
currently running a postgresql database, but it may be cumbersome for users
wanting to download and hack the sources. Maybe this could be solved using
some kind of embeddable database? Or maybe I could create several profiles
(never done this) and activate database tests only under demand?

Problem 2: Having database tests involves having configuration data written
down in some configuration file (the jdbc URL, user, password, etc.
hibernate.cfg.xml) or even in the pom (jdbc driver dependency). It's kind of
putting in the sources of the library some information that may be only of
interest to me in my current environment. How to solve this? Again using
some kind of embeddable datasource for tests? Using source filters? (again,
I haven't done this before, so I don't know if it's suitable)

Best regards
Jose



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org