[TIP] Asserting side effects for an integration test

Shawn Dahlen shawn.m.dahlen at gmail.com
Thu Dec 24 07:49:30 PST 2009


I'm looking for some advice on how to assert a side effect produced by
testing a function. Specifically, our project has a set of command objects
that internally use SQLAlchemy for database access. We would like to have a
set of integration tests that load a fixture (using the Fixture project)
into the database, execute the command, and assert the results. For commands
that return the result, this is straightforward. However, we are debating
how to assert commands that create, update, or delete data.

Option 1: In the test, call the CreateCommand then call the GetItemsCommand
asserting that the item count has increased. This keeps our test unaware of
the implementation detail but it breaks isolation for testing the
CreateCommand. My current thought is that this would be ok since it is an
integration test.

Option 2: In the test, call the CreateCommand. Subsequently, use a
SQLAlchemy query in the test to assert the change in database state. This
would keep each test isolated, but it now exposes implementation details.

Your advice would be appreciated. Thanks.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20091224/f5d5ab28/attachment.html>

More information about the testing-in-python mailing list