[TIP] Asserting side effects for an integration test
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
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...
More information about the testing-in-python