2014-09-01 63 views
3

我有我實現couchbase - 精簡版,Android的一個項目,它工作得很好,但是......我一直想在Robolectric添加到添加單元和組件測試工作,但還沒有任何運氣獲得這些兩個一起工作。目前我收到以下問題。調試:從jar中加載Android資源:C:\ Users \ brad.m2 \ repository \ org \ robolectric \ android-all \ 4.3_r2-robolectric-0 \ android-all-4.3_r2-robolectric-0。 jar!/ res ...有沒有人用couchbase-lite-android 1.02實現robolectric 2.3?

java.lang.UnsatisfiedLinkError: no com_couchbase_touchdb_TDCollateJSON in java.library.path 
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886) 
at java.lang.Runtime.loadLibrary0(Runtime.java:849) 
at java.lang.System.loadLibrary(System.java:1088) 
at com.couchbase.touchdb.TDCollateJSON.(TDCollateJSON.java:36) 
at com.couchbase.lite.android.AndroidSQLiteStorageEngine.open(AndroidSQLiteStorageEngine.java:46) 
at com.couchbase.lite.Database.open(Database.java:911) 
at com.couchbase.lite.Manager.getDatabase(Manager.java:227) 
at com.snapterm.core.models.transaction.TransactionsDb.initDatabase(TransactionsDb.java:61) 
at com.snapterm.core.models.transaction.TransactionsDb.(TransactionsDb.java:49) 
at com.snapterm.core.models.transaction.TransactionsDb.getInstance(TransactionsDb.java:41) 
at com.snapterm.core.SnapTerm.onCreate(SnapTerm.java:42) 
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:164) 
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:430) 
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.junit.runner.JUnitCore.run(JUnitCore.java:160) 
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) 
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) 
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 

無論我怎麼去手動嘗試加載這個lib,我都沒有修復這個錯誤的運氣。我相信這是Robolectric發現本地庫的一個限制,但是如果有人已經嘗試過這兩種方法並使它們成功地工作,那麼我很好奇。

+0

您是否設法讓它工作? – drspaceboo 2014-11-17 22:28:46

+0

@drspaceboo這個問題的解決方案發布了,它對我很有用。 – basudz 2015-01-14 00:45:49

+0

謝謝你讓我知道。我們已經離開Robolectric。我們希望能夠測試Couchbase本身,而不是將其抽象掉,所以我們不會在測試中使用它。 – drspaceboo 2015-01-15 00:53:55

回答

0

我從來沒有能夠實現圍繞Couchbase Robolectric測試覆蓋率,但是你可以在你使用依賴注入使用的東西,如匕首提供的同一項目中使用Couchbase和Robolectric。您需要做的是定義圍繞您使用的Couchbase的所有元素的接口,並且在您需要使用Couchbase的這些方面時使用接口,而不是在任何應用程序代碼中定義接口。然後,爲了讓Robolectric工作,您可以在測試模塊中實現接口的測試版本。

最後一步是你用匕首實際Couchbase類注入到你的主要應用模塊,並在您的測試應用程序模塊注入測試版本。這將允許您通過模擬數據庫層來編寫測試代碼。

+0

我試了一下,不得不圍繞我使用的所有Couchbase對象編寫包裝類。在更改我的代碼以使用這些包裝器之後,Robolectric能夠運行。我正在使用Dagger注入我的數據源,到目前爲止我的測試正在運行,所以感謝您的建議! – basudz 2015-01-14 00:43:52