Skip to content Skip to sidebar Skip to footer

How To Test Methods That Deal With Sqlite Database In Android?

I have made an application that deals with SQLite database by opening, retrieving data from, and inserting data to it. Now I want to test my methods. So , I have two classes, one '

Solution 1:

I know that it won't work with simple JUnit test

It will. Just call your methods as usual and check results for correctness.

The only important thing is that you should prefer to use IsolatedContext for your database creation. In this case your original database file from the app will remain unmodified. All tests will work with separate testing database file which can be modified or even deleted as many times as you want.

You can acquire proper IsolatedContext from ProviderTestCase2. (You can also look ProviderTestCase2 sources to understand how it works.)

Post a Comment for "How To Test Methods That Deal With Sqlite Database In Android?"