I'm trying to take a TDD approach in creating Android app. I'm using ORMLite and Mockito/Robolectric for testing. I've run into trouble testing a simple thing:
(method in some class wrapping up DAO calls)
public List<ITask> getTasksForNextTwoWeeks() throws SQLException {
// Code to be written
}
Well, the code inside will be just a proper query method call.
What's the best approach to test that code? I've been thinking about this, but can't think of solution without accessing the real database (whether real or test one).
Any suggestions welcome.
I am not fan of Gray's response, since it makes things little bit too complicated. I recommend you to simply create in-memory database instead, by passing null as a database name:
OrmLiteSqliteOpenHelper(context,null, null, DATABASE_VERSION );
That way you can test your queries in single test by
a) adding mock elements
b) testing if your SqliteOpenHelper
-wrapper returns correct results
Every test like that is completely independent from your actual database and other tests in your suite.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With