Unit tests and foreign key constraints

Поиск
Список
Период
Сортировка
От Andy Chambers
Тема Unit tests and foreign key constraints
Дата
Msg-id CAHnaAcw6vtqgJ0h-+pkfrzWoOPHHm5iBY-f-KDs3zJ0Z3sJ+xw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Unit tests and foreign key constraints
Re: Unit tests and foreign key constraints
Список pgsql-general
Hey All,

I've started trying to use foreign key constraints in my schema but it seems to make it more difficult to write unit tests that touch the database because each test now requires more setup data to satisfy the foreign key constraint. (I know some say your unit tests shouldn't touch the DB but the more full stack tests I have, the better I sleep at night :-))

I wondered if anyone else has run into this problem and found a good strategy to mitigate it. I thought I might be able to make these constraints deferred during a test run since I have automatic rollback after each test but even after "set constraints all deferred", I still got a foreign key violation during my test run if the test tries to insert data with a non-existent foreign key.

Cheers,
Andy

В списке pgsql-general по дате отправления:

Предыдущее
От: Jan de Visser
Дата:
Сообщение: Re: Allowing postgresql to accept 0xff syntax for data types that it makes sense for?
Следующее
От: Brian Dunavant
Дата:
Сообщение: Re: date with month and year