tags:

views:

233

answers:

2

I need to run unit tests for code that references SQLiteDatabase for my Android code; however all my attempts to instantiate this object outside the emulator (on my desktop machine) have failed. JDBC on Android is not being recommended on the Net, hence it's out of the question (I could have provided mock objects very easily that way). So, any ideas?

+1  A: 

You cannot test android classes outside the emulator or a real device. If you want to run test cases on your desktop computer, using JVM instead of Dalvik, they should be independent of android classes. You may also change android.jar not to throw exceptions, but I guess this is not what you want.

You may find these post helpful in creating mock contexts to run your DB tests:

dtmilano
I believe the best way forward is mocking android.db classes with JDBC - a bit weird but using JDBC *on the phone* is not recommended. This method would have to use different classpath for testing so classes using a desktop sqlite database come before android classes. I believe this could work. db.execSQL calls will map to statement.execute() calls one-to-one; Cursor delegation could be little tricky but manageable. In any case tho, some form of testing *must* be used for android.db calls. Sending code repeatedly to emulator for testing simply sucks.
burak bayramli
A: 

Hit the same issue and I agree with Burak. Did you make any progress with mocking up the android.db classes? You could also use sqlite4java on desktop but the issue is that it's difficult to provide a facade for the existing Android's SQLlite mock-up wrappers.

Kalle