Example Test SQLite Assets

An Example Test - SQLite Assets
You can see 4 of the important annotations here:
 * TestFixture - this class is a test suite
 * TestFixtureSetup - this code is always run before any of the tests are executed
 * TestFixtureTearDown - this code is always run after the tests are done executing, even if they fail.
 * Test - this method is a test

This Test is Flawed
There is also a flaw in the tests above, namely the subject under test (the  object  ) is used in the tests as well as the fixture setup. Consider the following scenario: the  has a caching mechanism keeps track of DB rows in memory. When rows are fetched, they are stored into the cache. When new rows are inserted or existing rows updated, the cache is updated, and eventually the cache is synced to disk.

Note that in the test above, all interactions with the database are handled by this  object. First, it's used to create the database and tables:

Then, in,   is called, with the intent to persist the asset to the database on disk. However to verify whether this operation succeeded,  is called:

Now assume a change introduced a bug that prevent the cache from being flushed to disk ever. The tests above would never discover this bug!

How to Fix the Flaw
Another means of populating the database and verifying the success of the operations performed by  object should be used instead. For example:

Similarly, to verify that the  object creates and retrieves assets properly, test   might be broken up into two tests:

This way  tests   only and   tests   only. If there are any problems in either of those methods or all of them, these tests will discover that there is a problem.