Reputation: 2182
I am unable to get started with using Robolectric unit tests because of the following error it has with couchbase db.
java.lang.UnsatisfiedLinkError: com.couchbase.lite.internal.database.sqlite.SQLiteConnection.nativeOpen(Ljava/lang/String;ILjava/lang/String;ZZ)J
This error is thrown in my CouchbaseWrapper class at syntax,
// Get existing db with that name
// or create a new one if it doesn't exist.
database = manager.getDatabase(dbname);
If I do database = manager.getDatabase(dbname, true);
, then this step "passes" but other steps return NPE.
Here is my testcase:
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class OnBoardingPageOneTest {
private OnboardingActivity onboardingActivity;
@Before
public void setUp() {
onboardingActivity = Robolectric.setupActivity(OnboardingActivity.class);
}
@Test
public void verifyElementsArePresent() {
assertThat(onboardingActivity.findViewById(R.id.text_container), is(not(null)));
assertThat(onboardingActivity.findViewById(R.id.intro_video_view), is(not(null)));
assertThat(onboardingActivity.findViewById(R.id.play_button), is(not(null)));
assertThat(onboardingActivity.findViewById(R.id.loading_progress), is(not(null)));
}
}
Log
Library not found: /native/osx/x86_64/libsqlcipher.dylib
Library not found: /native/osx/x86_64/libsqlite3.dylib
Library not found: /native/osx/x86_64/libsqlcipher.dylib
Library not found: /native/osx/x86_64/libsqlite3.dylib
java.lang.UnsatisfiedLinkError: com.couchbase.lite.internal.database.sqlite.SQLiteConnection.nativeOpen(Ljava/lang/String;ILjava/lang/String;ZZ)J
at com.couchbase.lite.internal.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at com.couchbase.lite.internal.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:194)
at com.couchbase.lite.internal.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:178)
at com.couchbase.lite.internal.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:461)
at
Upvotes: 4
Views: 480
Reputation: 6715
I don't believe that there is any way to run Couchbase Lite Android on Robolectric.
The problem is that in order to do, essentially, anything at all, Couchbase Lite has to load a native code engine, LiteCore. LiteCore is written in C++ and is included in the Couchbase Lite Android aar. The Android system unpacks the native library and puts it in a place from which it can be loaded, when the aar is installed.
Robolectric does not do this. As a result the library cannot be loaded and any JNI calls will fail.
Upvotes: 0