Realm Unit Test on Android
<p>Trying to unit test a class that does some calls to Realm (0.87.4), the test setup fails with</p>

<pre><code>java.lang.NoClassDefFoundError: rx/Observable$OnSubscribe
at io.realm.RealmConfiguration$Builder.&lt;init&gt;(RealmConfiguration.java:279)
at org.testapp.db.MyClassTest.setUp(MyClassTest.java:34)
... 
Caused by: java.lang.ClassNotFoundException: rx.Observable$OnSubscribe
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
</code></pre>

<p>My test class starts with:</p>

<pre><code>@RunWith(MockitoJUnitRunner.class)
public class MyClassTest extends TestCase {

@Rule
public TemporaryFolder testFolder = new TemporaryFolder();

Realm realm;

@Before
public void setUp() throws Exception {
    File tempFolder = testFolder.newFolder("realmdata");
    RealmConfiguration config = new RealmConfiguration.Builder(tempFolder).build();

    realm = Realm.getInstance(config);
}
...
</code></pre>

<p>My gradle has:</p>

<pre><code>testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.10.19"
testCompile "org.robolectric:robolectric:3.0"
compile 'io.realm:realm-android:0.87.4'
</code></pre>

<p>How to solve this?</p>

<p><strong>=== EDIT 1 ===</strong></p>

<p>I added to my gradle: </p>

<pre><code>testCompile 'io.reactivex:rxjava:1.1.0'
</code></pre>

<p>and</p>

<pre><code>android {
  // ...
  testOptions { 
    unitTests.returnDefaultValues = true
  }
}
</code></pre>

<p>the new error is</p>

<pre><code>java.lang.UnsatisfiedLinkError: no realm-jni 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 io.realm.internal.RealmCore.loadLibrary(RealmCore.java:117)
</code></pre>