DBUnit + Derby

View: New views
4 Messages — Rating Filter:   Alert me  

DBUnit + Derby

by Junk Catcher :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can anyone shed some light on how I might be able to overcome an issue I have.

I have a bunch of unit test that act on a database. Before I was coding by myself and used mysql. I have now expanded my project to include others and we're attempting to use Apache Derby for the DB during development.
However, now that I have made the switch, many of my unit test fail. I have read that Derby checks for foreign key violations right away and not at the time of the commit (end of transaction). However, since DBUnit seems to reset the database in no particular order, I get violations all over the place and thus the 'reset' is rolled back.

An example:

I have a STORE table and an EMPLOYEE table. There is a column in the EMPLOYEE table that points to the STORE_ID. The constaint is that the EMPLOYEE must belong to a store (can't have employees belonging to stores that don't exist!). However, if DBUnit attempts to wipe the STORE table first, the EMPLOYEE table gets a FK_VIOLATION since it now points to a store that doesn't exist. The whole reset fails and thus my next test that involves these tables fails.

This was NOT a problem with MySQL, since it waits until the transaction end to check everything and since by that time the EMPLOYEE is also deleted, there is no violation.

I realize this is more of a problem belonging to how Derby decided to do their implementation, but does any one have a work around, other than switching back to a heavy weight database?


Noel Murphy

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user

Re: DBUnit + Derby

by Robert Crawford-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Don't declare the foreign keys on your unit test database. Your tests  
aren't testing the constraint declarations; they're testing the code,  
so the constraints aren't necessary.

On Jul 31, 2008, at 2:15 PM, Junk Catcher wrote:

> Can anyone shed some light on how I might be able to overcome an  
> issue I have.
>
> I have a bunch of unit test that act on a database. Before I was  
> coding by myself and used mysql. I have now expanded my project to  
> include others and we're attempting to use Apache Derby for the DB  
> during development.
> However, now that I have made the switch, many of my unit test fail.  
> I have read that Derby checks for foreign key violations right away  
> and not at the time of the commit (end of transaction). However,  
> since DBUnit seems to reset the database in no particular order, I  
> get violations all over the place and thus the 'reset' is rolled back.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user

Re: DBUnit + Derby

by Junk Catcher :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The problem there is that I'm using hibernate and letting it generate the tables / schema for me. So while it is true that the unit test are testing code, they are also testing the database schema in a sense.
I also don't want to have one set of hibernate config files for development and then another for production. That is a maintenance nightmare and it breaks the purpose of running automated tests. (testing one scenario in development while deploying to another).



On Thu, Jul 31, 2008 at 3:19 PM, Robert Crawford <crawford@...> wrote:
Don't declare the foreign keys on your unit test database. Your tests
aren't testing the constraint declarations; they're testing the code,
so the constraints aren't necessary.

On Jul 31, 2008, at 2:15 PM, Junk Catcher wrote:

> Can anyone shed some light on how I might be able to overcome an
> issue I have.
>
> I have a bunch of unit test that act on a database. Before I was
> coding by myself and used mysql. I have now expanded my project to
> include others and we're attempting to use Apache Derby for the DB
> during development.
> However, now that I have made the switch, many of my unit test fail.
> I have read that Derby checks for foreign key violations right away
> and not at the time of the commit (end of transaction). However,
> since DBUnit seems to reset the database in no particular order, I
> get violations all over the place and thus the 'reset' is rolled back.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user

Re: DBUnit + Derby

by diongillard :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We use the csv dataset support in dbunit, and it allows you to specify
a table ordering file to tell dbunit in which order to load data.

On Fri, Aug 1, 2008 at 5:37 AM, Junk Catcher <catchall@...> wrote:

> The problem there is that I'm using hibernate and letting it generate the
> tables / schema for me. So while it is true that the unit test are testing
> code, they are also testing the database schema in a sense.
> I also don't want to have one set of hibernate config files for development
> and then another for production. That is a maintenance nightmare and it
> breaks the purpose of running automated tests. (testing one scenario in
> development while deploying to another).
>
>
>
> On Thu, Jul 31, 2008 at 3:19 PM, Robert Crawford <crawford@...>
> wrote:
>>
>> Don't declare the foreign keys on your unit test database. Your tests
>> aren't testing the constraint declarations; they're testing the code,
>> so the constraints aren't necessary.
>>
>> On Jul 31, 2008, at 2:15 PM, Junk Catcher wrote:
>>
>> > Can anyone shed some light on how I might be able to overcome an
>> > issue I have.
>> >
>> > I have a bunch of unit test that act on a database. Before I was
>> > coding by myself and used mysql. I have now expanded my project to
>> > include others and we're attempting to use Apache Derby for the DB
>> > during development.
>> > However, now that I have made the switch, many of my unit test fail.
>> > I have read that Derby checks for foreign key violations right away
>> > and not at the time of the commit (end of transaction). However,
>> > since DBUnit seems to reset the database in no particular order, I
>> > get violations all over the place and thus the 'reset' is rolled back.
>>
>>
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>> challenge
>> Build the coolest Linux based applications with Moblin SDK & win great
>> prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the
>> world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> dbunit-user mailing list
>> dbunit-user@...
>> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> dbunit-user mailing list
> dbunit-user@...
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>
>



--
dIon Gillard
There are only two kinds of programming languages: those people always
bitch about and those nobody uses. (Bjarne Stroustrup)

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user
LightInTheBox - Buy quality products at wholesale price!