dbunit: use case issues

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

dbunit: use case issues

Antonio Diaz Sanchez
 Hi,

 I would like to ask you about good practices using "dbUnit". There are some issues that lead me to think that maybe I am not using it in a right way.

 For example, I want to test a Class that makes searches. In my opinion, the best way to test it is to set several input files; each of them test a use case of the search algorithm. However, the life cycle of dbUnit is configured to get only one, which is loaded through the "getDataSet" method. As a result, I am required to implement this method, even though it is useless for my porpuse.

 On the other hand, I don't understand why the connection to the database is not saved into a member variable after being read through the "getConnection" method. If I am not wrong, it is common to use the connection during the tests, so keeping a reference is necessary. And in order to achieve it, I have to override the "setUp" method.

 It seems to me that the life cycle of the class "DatabaseTestCase" is configured for a simple case that is hardly ever common.

 Any suggestions?

 Regards,


     

------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: dbunit: use case issues

John Hurst-2
Antonio,

Personally, I agree that the "normal" lifecycle of some of DbUnit's provided base classes is not the pattern I would follow.

In my projects I use a project-specific base class instead, which handles some of these issues you raise.

Regarding datasets per-test, the approach I usually take is:
  - Define a "standard" set of stable data that are common to most/all tests.  In my environment this works well for reference or lookup data. I put these data in a FlatXmlDataSet and load them for all tests.
  - Define per-test data inline in each test. Here I prefer *not* to use FlatXmlDataSet or any of the other "file based" datasets. Instead I embed my test data as CSV strings in the tests they apply to. This keeps the test data with the test, and in my projects it's led to much clearer and more maintainable tests.

I've written about some of this stuff in the chapter I wrote for "Java Power Tools".

I put some comments specifically for using DbUnit with Grails in my blog at

  http://skepticalhumorist.blogspot.com/2009/07/inline-data-for-dbunit-tests-in-grails.html

I need to write up some more of this and put it in the DbUnit site -- it's on my list of things to do!

I do believe that different projects have different needs. No doubt many projects do work well with the standard DbUnit provided base classes. Mine haven't tended to work out that way though.

Regards

John Hurst


On Mon, May 17, 2010 at 9:00 PM, Antonio Diaz Sanchez <[hidden email]> wrote:
 Hi,

 I would like to ask you about good practices using "dbUnit". There are some issues that lead me to think that maybe I am not using it in a right way.

 For example, I want to test a Class that makes searches. In my opinion, the best way to test it is to set several input files; each of them test a use case of the search algorithm. However, the life cycle of dbUnit is configured to get only one, which is loaded through the "getDataSet" method. As a result, I am required to implement this method, even though it is useless for my porpuse.

 On the other hand, I don't understand why the connection to the database is not saved into a member variable after being read through the "getConnection" method. If I am not wrong, it is common to use the connection during the tests, so keeping a reference is necessary. And in order to achieve it, I have to override the "setUp" method.

 It seems to me that the life cycle of the class "DatabaseTestCase" is configured for a simple case that is hardly ever common.

 Any suggestions?

 Regards,




------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



--
Life is interfering with my game

------------------------------------------------------------------------------


_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: dbunit: use case issues

Jeff Jensen-2

In addition to John’s good suggestions, look at the PrepAndExpectedTestCase/DefaultPrepAndExpectedTestCase class in trunk.  It sets some things up a little bit more, possibly towards what you are looking for.

 

 

From: John Hurst [mailto:[hidden email]]
Sent: Monday, May 17, 2010 4:43 AM
To: [hidden email]
Subject: Re: [dbunit-user] dbunit: use case issues

 

Antonio,

Personally, I agree that the "normal" lifecycle of some of DbUnit's provided base classes is not the pattern I would follow.

In my projects I use a project-specific base class instead, which handles some of these issues you raise.

Regarding datasets per-test, the approach I usually take is:
  - Define a "standard" set of stable data that are common to most/all tests.  In my environment this works well for reference or lookup data. I put these data in a FlatXmlDataSet and load them for all tests.
  - Define per-test data inline in each test. Here I prefer *not* to use FlatXmlDataSet or any of the other "file based" datasets. Instead I embed my test data as CSV strings in the tests they apply to. This keeps the test data with the test, and in my projects it's led to much clearer and more maintainable tests.

I've written about some of this stuff in the chapter I wrote for "Java Power Tools".

I put some comments specifically for using DbUnit with Grails in my blog at

  http://skepticalhumorist.blogspot.com/2009/07/inline-data-for-dbunit-tests-in-grails.html

I need to write up some more of this and put it in the DbUnit site -- it's on my list of things to do!

I do believe that different projects have different needs. No doubt many projects do work well with the standard DbUnit provided base classes. Mine haven't tended to work out that way though.

Regards

John Hurst

On Mon, May 17, 2010 at 9:00 PM, Antonio Diaz Sanchez <[hidden email]> wrote:

 Hi,

 I would like to ask you about good practices using "dbUnit". There are some issues that lead me to think that maybe I am not using it in a right way.

 For example, I want to test a Class that makes searches. In my opinion, the best way to test it is to set several input files; each of them test a use case of the search algorithm. However, the life cycle of dbUnit is configured to get only one, which is loaded through the "getDataSet" method. As a result, I am required to implement this method, even though it is useless for my porpuse.

 On the other hand, I don't understand why the connection to the database is not saved into a member variable after being read through the "getConnection" method. If I am not wrong, it is common to use the connection during the tests, so keeping a reference is necessary. And in order to achieve it, I have to override the "setUp" method.

 It seems to me that the life cycle of the class "DatabaseTestCase" is configured for a simple case that is hardly ever common.

 Any suggestions?

 Regards,




------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game


------------------------------------------------------------------------------


_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: dbunit: use case issues

Antonio Diaz Sanchez
In reply to this post by John Hurst-2
Thank both of you for the comments and the links. These have been
useful. I will continue making tests and trying to write down these bit
issues in order to get some insight.


Regards,


El 05/17/2010 10:42 AM, John Hurst escribió:

> Antonio,
>
> Personally, I agree that the "normal" lifecycle of some of DbUnit's
> provided base classes is not the pattern I would follow.
>
> In my projects I use a project-specific base class instead, which
> handles some of these issues you raise.
>
> Regarding datasets per-test, the approach I usually take is:
>    - Define a "standard" set of stable data that are common to most/all
> tests.  In my environment this works well for reference or lookup data.
> I put these data in a FlatXmlDataSet and load them for all tests.
>    - Define per-test data inline in each test. Here I prefer *not* to
> use FlatXmlDataSet or any of the other "file based" datasets. Instead I
> embed my test data as CSV strings in the tests they apply to. This keeps
> the test data with the test, and in my projects it's led to much clearer
> and more maintainable tests.
>
> I've written about some of this stuff in the chapter I wrote for "Java
> Power Tools".
>
> I put some comments specifically for using DbUnit with Grails in my blog at
>
> http://skepticalhumorist.blogspot.com/2009/07/inline-data-for-dbunit-tests-in-grails.html
>
> I need to write up some more of this and put it in the DbUnit site --
> it's on my list of things to do!
>
> I do believe that different projects have different needs. No doubt many
> projects do work well with the standard DbUnit provided base classes.
> Mine haven't tended to work out that way though.
>
> Regards
>
> John Hurst
>
>
> On Mon, May 17, 2010 at 9:00 PM, Antonio Diaz Sanchez
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>       Hi,
>
>       I would like to ask you about good practices using "dbUnit". There
>     are some issues that lead me to think that maybe I am not using it
>     in a right way.
>
>       For example, I want to test a Class that makes searches. In my
>     opinion, the best way to test it is to set several input files; each
>     of them test a use case of the search algorithm. However, the life
>     cycle of dbUnit is configured to get only one, which is loaded
>     through the "getDataSet" method. As a result, I am required to
>     implement this method, even though it is useless for my porpuse.
>
>       On the other hand, I don't understand why the connection to the
>     database is not saved into a member variable after being read
>     through the "getConnection" method. If I am not wrong, it is common
>     to use the connection during the tests, so keeping a reference is
>     necessary. And in order to achieve it, I have to override the
>     "setUp" method.
>
>       It seems to me that the life cycle of the class "DatabaseTestCase"
>     is configured for a simple case that is hardly ever common.
>
>       Any suggestions?
>
>       Regards,
>
>
>
>
>     ------------------------------------------------------------------------------
>
>     _______________________________________________
>     dbunit-user mailing list
>     [hidden email]
>     <mailto:[hidden email]>
>     https://lists.sourceforge.net/lists/listinfo/dbunit-user
>
>
>
>
> --
> Life is interfering with my game
>
>
>
> ------------------------------------------------------------------------------
>
>
>
>
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user


               
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com

------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user