How to unit test Content provider and DB calls in robolectric which has native dependencies

506 views Asked by At

I want to use robolectric(3+) for unit testing in my project. The issue is that in our project we are not using the sqlite dependencies from android.database.sqlite but the compiled source code from sqlite project(org.sqlite.database). This is because we are using hardware based encryption in our DB for security. The dependencies on org.sqlite.database calls native code. Robolectric does not support any external native code(will give java.lang.UnsatisfiedLinkError). The ContentProvider and SQLite helper class in my project references the code in org.sqlite.database packages for creating tables, building queries, table joins. Now, I can create another content provider for test cases, but it can cause code duplication and it won't be testing the actual content provider. Within the content provider, I can separate DB operations into different classes but again it will be code duplication. It seems like I have to run them as instrumented test cases. If anybody has some suggestions, it will be great.

1

There are 1 answers

0
Kanishk On BEST ANSWER

We are running those tests as instrumented tests. Currently robolectric does not support any outside native code and gives this error when trying to access any native method. So there was no other option other than to run all the DB related unit tests on a device.