Re: Unit tests and foreign key constraints

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Dave Owens <dave(at)teamunify(dot)com>
Cc: achambers(dot)home(at)googlemail(dot)com, pgsql-general(at)postgresql(dot)org
Subject: Re: Unit tests and foreign key constraints
Date: 2015-05-21 21:29:20
Message-ID: 20150521212920.GB18278@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, May 21, 2015 at 01:33:46PM -0700, Dave Owens wrote:
> >
> > 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 :-))
> >
>
> Unit tests really should be about testing individual bits of logic. Does a
> single method do the desired thing, and not the undesired thing...
> Ideally, your data access layer should be interchangeable, ie: use a real
> database record in production, but use a mock database record for unit
> tests.

Nice in theory. But if you use Postgres features like timestamptz
calculations and hstore, it's generally way easier to run your unit
tests on an actual PostgreSQL database. Otherwise you're going to spend
all your time working around the fact that your mock database is not
the real thing (and running into bugs in your emulation layer).

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
-- Arthur Schopenhauer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paul Jungwirth 2015-05-21 21:33:45 Re: date with month and year
Previous Message Karsten Hilbert 2015-05-21 21:27:34 Re: date with month and year