[odb-users] Unit Testing and ODB

Boris Kolpackov boris at codesynthesis.com
Tue Aug 14 09:15:40 EDT 2012


Hi Davide,

Davide Anastasia <Davide.Anastasia at qualitycapital.com> writes:

> I am wondering whether there is any way to programmatically control the
> content of a database in order to write "well define" unit testing.
> 
> In particular, I wrote a function that retrieves an object if available,
> or adds it to the database and I want to be sure that the database
> doesn't contain that object before running my tests (using some kind of
> fixture).

I am not clear what kind of functionality you are looking for here. You
can make sure that the database is empty by re-creating the schema (i.e.,
dropping all the tables and re-creating them). After that, if your tests
expect some content in the database, then you will need to add it using
the standard ODB mechanisms. This is how ODB's own test suite does it.

Now, if you want to do this many times during your test execution,
then embedded (into C++) schema creation code will probably be more
convenient than a standalone SQL file. You can also partition your
schema into segments if you don't want to re-create the while
database for every test (which could be slow). For more information
on this functionality refer to Section 3.3, "Database" in the ODB
manual.

Boris



More information about the odb-users mailing list