Question

I have an OrmLiteBaseActivity and in the onCreate() of this activity i read some data from a database. Depending on the data read I change the visibility of some views.

I'm writing tests for this activity. How can I mock the database (or even use another test database) so I can change the data in the database according to my tests needs so I can test different cases depending on that data. I want to test the visibility of the views depending on the data read.

Any ideas, guides, examples or anything else that will help me is welcomed :)

Was it helpful?

Solution

I'm writing tests for this activity. How can I mock the database (or even use another test database) so I can change the data in the database according to my tests needs so I can test different cases depending on that data.

All of the database stuff is driven internally to ORMLite with 4 interfaces:

When you construct your DAOs, you pass in a ConnectionSource implementation that gives DatabaseConnections, etc.. You can certain use EasyMock or some little concrete class to mock out these 4 interfaces. It's a little complex to do so but it can be done.

The unit tests for ORMLite are pretty extensive. For some partial examples you can take a look at:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top