Re: How to test databases with foreign key constraints?
>I am actually solving this exact problem - if you can get rid of the
> I'm just wondering how do I test a database insertion/updation
> method when there are foreign key constraints on the data? Inserting
> all the dependant data seems painful to me. Is there any other way I
> can quickly test the method I want to test, without bothering about
> all the foreign key constraints?
constraints I would recommend doing it since it makes testing easier -
and I came up with a solution using typed datasets in Dot.Net. There
is an excellent example in "Test Drive Development in Microsoft.Net".
If you cannot use typed datasets and want to avoid this very real
hassle of adding data you are not interested in, consider using mock
objects for the database. The mock objects will ensure that your
database calls are correct, but will not give you the complete
satisfaction as an integration test through a database.
If none of these ideas appeal to you, then you are stuck with the
problem you are describing.