Take the 2-minute tour ×

I have an android application and my tester is learning how to implement tests using robotium. The application has an entity (object/pojo) stored in a sqlite database with id, description and some other info.

We need to some how do a setup in the test classes so that the application has one entity with a determined id, description, etc that can be used in the testing.

For the database access we have a Dao Pattern implemented + a extension of SQLiteOpenHelper create and manage updates to the database that gets injected in the Activity classes using Robo Guice. So far we're not using ContentProviders (There is a MockContentProvider class in the android test package), but if that is the best solution we might migrate to that.

The requirement for the setup implementation is not to mix test code with the app code. Any suggestions?

share|improve this question
add comment

1 Answer

I am not sure exactly what you mean by "The requirement for the setup implementation is not to mix test code with the app code. Any suggestions?" but im guessing you mean you do not want to reuse any code in the application in the tests???

Well I am afraid your best bet is then going to be have your either write code to populate the database, or have them exercise the application to get it into a given state then test. Personally Reusing your code might be the best option but you have to frame it in the right way and depends on what you are trying to test. For example, if you are testing that something in the database gets displayed properly then reusing our code is fine. If you was testing that putting stuff into the database works then reusing your code is not fine, you should then exercise the application to ensure it saves to the database properly.

The way i like to look at this is in the BDD style, anything in the "Given" steps happened in the past, your test should not care how it happened just that it happened so how it came to be in that state is not important, in these cases speed is probably the most important part.

share|improve this answer
add comment

Your Answer


