Different dataset for each testcase

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

Different dataset for each testcase

uravi
Hi,

I am trying to do a DBUnit where in a single test class, I have multiple testXXX() methods. Each test method requires me to create a  different IDataSet. But the getDataSet() overridden method can handle only one dataset. Is there a way I can implement this ?

Any suggestions/examples would be really helpful

Thanks for your help
Uma
 
Reply | Threaded
Open this post in threaded view
|

Re: Different dataset for each testcase

John Hurst-2
You can definitely do this -- actually it's how I do most of my DbUnit tests.

Unfortunately it's a little more complicated -- you don't extend DBTestCase, but rather delegate to a DbUnit class in your test. I need to write some examples to show how to do this. 

Regards

John Hurst
Wellington, New Zealand

On Thu, Jun 2, 2011 at 6:57 AM, uravi <[hidden email]> wrote:

Hi,

I am trying to do a DBUnit where in a single test class, I have multiple
testXXX() methods. Each test method requires me to create a  different
IDataSet. But the getDataSet() overridden method can handle only one
dataset. Is there a way I can implement this ?

Any suggestions/examples would be really helpful

Thanks for your help
Uma

--
View this message in context: http://old.nabble.com/Different-dataset-for-each-testcase-tp31752231p31752231.html
Sent from the DBUnit - Users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



--
Life is interfering with my game

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Different dataset for each testcase

uravi
 Hi John,

Thank you for your response.  If you can send me some example code on how to achieve this it would be really great. When you say delegate do you you use Spring framework to achieve this ?

Thank you for your help
Uma

John Hurst-2 wrote
You can definitely do this -- actually it's how I do most of my DbUnit
tests.

Unfortunately it's a little more complicated -- you don't extend DBTestCase,
but rather delegate to a DbUnit class in your test. I need to write some
examples to show how to do this.

Regards

John Hurst
Wellington, New Zealand

On Thu, Jun 2, 2011 at 6:57 AM, uravi <uravi@ucdavis.edu> wrote:

>
> Hi,
>
> I am trying to do a DBUnit where in a single test class, I have multiple
> testXXX() methods. Each test method requires me to create a  different
> IDataSet. But the getDataSet() overridden method can handle only one
> dataset. Is there a way I can implement this ?
>
> Any suggestions/examples would be really helpful
>
> Thanks for your help
> Uma
>
> --
> View this message in context:
> http://old.nabble.com/Different-dataset-for-each-testcase-tp31752231p31752231.html
> Sent from the DBUnit - Users mailing list archive at Nabble.com.
>
>
>
> ------------------------------------------------------------------------------
> Simplify data backup and recovery for your virtual environment with
> vRanger.
> Installation's a snap, and flexible recovery options mean your data is
> safe,
> secure and there when you need it. Data protection magic?
> Nope - It's vRanger. Get your free trial download today.
> http://p.sf.net/sfu/quest-sfdev2dev
> _______________________________________________
> dbunit-user mailing list
> dbunit-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>



--
Life is interfering with my game

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
dbunit-user mailing list
dbunit-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Different dataset for each testcase

John Hurst-2
I usually use Spring in database apps and testing these days. But it is a convenience, not a necessity, in relation to DbUnit.

I found a sample I did that shows one way to do this.

I've attached the AbstractDbUnitTestCase from the sample, which shows how you can manage the DataSource and instantiate DbUnit classes to perform operations and create DataSets.

Here's an example of the usage:

public class SpringJdbcOfficeDaoTest extends AbstractDbUnitTestCase {
  @Test
  public void testFind() throws Exception {
    DatabaseOperation.CLEAN_INSERT.execute(getDatabaseConnection(), getDataSet("SpringJdbcOfficeDaoTest-setup.xml"));
    OfficeDao dao = new SpringJdbcOfficeDao(getDataSource());
    Office office = dao.find("AUCK");
    assertEquals("AUCK", office.getOfficeCode());
    assertEquals("Auckland", office.getCity());
    // ... more assertions
  }

  // ... more tests
}

I recommend you write your own base class for this kind of thing in your project. You can put any special DbUnit requirements you have in it, such as feature customization.

John Hurst
Wellington, New Zealand

On Thu, Jun 2, 2011 at 10:25 AM, uravi <[hidden email]> wrote:

 Hi John,

Thank you for your response.  If you can send me some example code on how to
achieve this it would be really great. When you say delegate do you you use
Spring framework to achieve this ?

Thank you for your help
Uma


John Hurst-2 wrote:
>
> You can definitely do this -- actually it's how I do most of my DbUnit
> tests.
>
> Unfortunately it's a little more complicated -- you don't extend
> DBTestCase,
> but rather delegate to a DbUnit class in your test. I need to write some
> examples to show how to do this.
>
> Regards
>
> John Hurst
> Wellington, New Zealand
>
> On Thu, Jun 2, 2011 at 6:57 AM, uravi <[hidden email]> wrote:
>
>>
>> Hi,
>>
>> I am trying to do a DBUnit where in a single test class, I have multiple
>> testXXX() methods. Each test method requires me to create a  different
>> IDataSet. But the getDataSet() overridden method can handle only one
>> dataset. Is there a way I can implement this ?
>>
>> Any suggestions/examples would be really helpful
>>
>> Thanks for your help
>> Uma
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Different-dataset-for-each-testcase-tp31752231p31752231.html
>> Sent from the DBUnit - Users mailing list archive at Nabble.com.
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Simplify data backup and recovery for your virtual environment with
>> vRanger.
>> Installation's a snap, and flexible recovery options mean your data is
>> safe,
>> secure and there when you need it. Data protection magic?
>> Nope - It's vRanger. Get your free trial download today.
>> http://p.sf.net/sfu/quest-sfdev2dev
>> _______________________________________________
>> dbunit-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>>
>
>
>
> --
> Life is interfering with my game
>
> ------------------------------------------------------------------------------
> Simplify data backup and recovery for your virtual environment with
> vRanger.
> Installation's a snap, and flexible recovery options mean your data is
> safe,
> secure and there when you need it. Data protection magic?
> Nope - It's vRanger. Get your free trial download today.
> http://p.sf.net/sfu/quest-sfdev2dev
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>
>

--
View this message in context: http://old.nabble.com/Different-dataset-for-each-testcase-tp31752231p31753703.html
Sent from the DBUnit - Users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



--
Life is interfering with my game

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user

AbstractDbUnitTestCase.java (2K) Download Attachment