I've written several unit tests for an already existing DatabaseOpenHelper
class. I covered the creation scenario and migration from old schema to new one. Unfortunately, I don't feel that my tests are good. For example, for DB creation I check that SQLiteDatabase. execSQL()
was called three times (we have three tables so far) and check that query string is in set of specified SQL strings.
The issue so far – if someone changes order of columns the test will fail. Probably this is OK.
But what are other ways of SQL schema unit testing? Or don't you have unit tests for that, and rely only on the integration one?
Best Answer
Instead of verifying that
i would just test if these colums exist after upgrade.
To do this I would create an integration test that
Example:
Test-Success means there is no database-exception for unknown table or field.
[Update 2.2.2013] Unittesting the DatabaseOpenHelper (Unittest=Testing in isolation) would requre to test without a real database and verifying that the database update script is valid or at least contain all neccessary fields/tables. In my opinion this is to much work. Integration testing with a real database is much easier.